[英]What's the difference between a function constructor and prototype constructor?
[英]What is a constructor function's prototype?
說,我有一個名為MyClass
的構造函數。 我用它創建了一個對象obj
。 obj
繼承自MyClass.prototype
。 所以這是我的問題:
MyClass.prototype
來自哪里? 它只是具有constructor
屬性的普通對象嗎?
感謝您的回答。
// 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.