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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -