javascript - Understanding prototype Property of function -
taken example if
var func = function(){} here func has property called prototype , can add custom methods following.
func.prototype.move = function(){ //do } as per understanding here prototype property of func default provided interpreter , not used delegate functionality, ie. there nothing like
func.move() applying same logic creating property of same function following
func.method = function(){ //do } now if create new object
var obj = new func(); here there obj.move() obj.method() wont there. if prototype property no magical advantages why behavior ?? in advance !
when use new prototype property of function used template internal [[prototype]] property of instance object. exposed in browsers __proto__, not confuse prototype again, regular property.
when attach property function directly, opposed prototype, using function namespace. since functions objects, can have arbitrary properties, , others built-in, prototype , name example. in effect creating similar static method, 1 doesn't depend on instance, doesn't use this.
Comments
Post a Comment