Reputation: 618
Say, I have a constructor function called MyClass
. And I create an object obj
out of it. obj
inherits from MyClass.prototype
. So here is my question:
Where is the
MyClass.prototype
from? Is it just a plain object with aconstructor
property?
Thanks for your answers.
// Constructor
function MyClass() {
}
var obj = new MyClass;
// object inherits from MyClass.prototype
obj.__proto__ == MyClass.prototype;
// => true
// MyClass.prototype inherits from Object.prototype
MyClass.prototype.__proto__ == Object.prototype;
// => true
Upvotes: 0
Views: 62
Reputation: 665574
Where is the
MyClass.prototype
from?
It's implicitly created when the function object (MyClass
) is created.
Is it just a plain object with a
constructor
property?
Yes, exactly. No more than that, no magic involved :-)
Upvotes: 2
Reputation: 20455
Upvotes: 0