javascript - What is a constructor function's prototype? -
say, have constructor function called myclass. , create object obj out of it. obj inherits myclass.prototype. here question:
where
myclass.prototypefrom? plain objectconstructorproperty?
thanks answers.
// constructor function myclass() { } var obj = new myclass; // object inherits myclass.prototype obj.__proto__ == myclass.prototype; // => true // myclass.prototype inherits object.prototype myclass.prototype.__proto__ == object.prototype; // => true
where
myclass.prototypefrom?
it's implicitly created when function object (myclass) created.
is plain object
constructorproperty?
yes, exactly. no more that, no magic involved :-)
Comments
Post a Comment