javascript - Why my prototype chain become broken? -
i'am learnig javascript , need understand happens in browser. have 3 js classes:
function a(){} function b(){} function c(){} b.prototype = new a(); c.prototype = new b(); = new a(); // instanceof b = new b(); // b instanceof a,b c = new c(); // c instanceof a,b,c
but when call:
a.prototype = new c(); // not instanceof // b not instanceof // c not instanceof // c instanceof b
could please me understand happens when build such cycle prototype chain , why breaks existing prototype chain?
update: i've found special method prototype of object, makes not easier understand.
object.getprototypeof(a) // a{} object.getprototypeof(b) // a{} object.getprototypeof(c) // b{}
you have circular reference, when add a.prototype = new c();
:
a references b b references c c references a references b etc...
that's why code breaks, since can not work, there's no fix it, know of.
Comments
Post a Comment