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);
中结果为 false 的原因 最佳答案
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
关于javascript - 原型(prototype)链是如何工作的?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27216394/