【发布时间】:2014-11-30 18:02:53
【问题描述】:
var A = {};
var B = Object.create(A);
var C = Object.create(B);
A.isPrototypeOf(C);//returns true
C.isPrototypeOf(A);//returns false
在上面的代码中,我不明白C.isPrototypeOf(A);中结果为假的原因
【问题讨论】:
标签: javascript
var A = {};
var B = Object.create(A);
var C = Object.create(B);
A.isPrototypeOf(C);//returns true
C.isPrototypeOf(A);//returns false
在上面的代码中,我不明白C.isPrototypeOf(A);中结果为假的原因
【问题讨论】:
标签: javascript
var A = {}; // A inherits Object
var B = Object.create(A); // B inherits A inherits Object
var C = Object.create(B); // C inherits B inherits A inherits Object
// Does C inherit A?
A.isPrototypeOf(C); // true, yes
// C inherits A because B inherits A and C inherits B
// Does A inherit C?
C.isPrototypeOf(A); // false, no
// A only inherits Object
【讨论】:
C 是 B 的“后代”,它是 A 的“后代”。 C怎么可能是A的原型?
由于C最终继承自A,而A从C中得不到任何东西,那么“C是A的原型”是错误的
【讨论】: