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

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -