function Person(name) {
this.name = name;
}
var rob = new Person('Rob');__proto__)是Person.prototype,所以罗伯是一个人。但
console.log(Person.prototype);输出
Person {}Person.prototype是一个对象吗?阵列?一个人?
如果它是一个对象,那么这个原型也有一个原型吗?
更新我从这个问题中学到的东西(2014年1月24日星期五,上午11:38:26 )
function Person(name) {
this.name = name;
}
var rob = new Person('Rob');
// Person.prototype references the object that will be the actual prototype (x.__proto__)
// for any object created using "x = new Person()". The same goes for Object. This is what
// Person and Object's prototype looks like.
console.log(Person.prototype); // Person {}
console.log(Object.prototype); // Object {}
console.log(rob.__proto__); // Person {}
console.log(rob.__proto__.__proto__); // Object {}
console.log(typeof rob); // object
console.log(rob instanceof Person); // true, because rob.__proto__ == Person.prototype
console.log(rob instanceof Object); // true, because rob.__proto__.__proto__ == Object.prototype
console.log(typeof rob.__proto__); // object
console.log(rob.__proto__ instanceof Person); // false
console.log(rob.__proto__ instanceof Object); // true, because rob.__proto__.__proto__ == Object.prototype发布于 2014-01-23 04:42:08
typeof Person === "function"
typeof Person.prototype === "object"https://stackoverflow.com/questions/21299416
复制相似问题