javascript - Where can I place prototype property as per my below code? -


i have writtern 2 different ways , both giving me same result , can use when ?

first example

var basecls = function() {   basecls.prototype.name = "john"; }; var justcls = new basecls(); console.log(justcls.name); // giving result john 

second example

var basecls = function() {}; basecls.prototype.name = "john"; var justcls = new basecls(); console.log(justcls.name); // giving result john 

both giving me same result want know there other criteria lead write property / method prototype inside / outside main function ?

thanks consideration

you should change prototype outside constructor. otherwise change every time create instance.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -