javascript - Where can I place prototype property as per my below code? -
this question has answer here:
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
Post a Comment