原型链如何工作?

博詹德拉·拉尼雅
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);

保罗·S。
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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章