How does the prototype chain work?

var A = {};
var B = Object.create(A);
var C = Object.create(B);
A.isPrototypeOf(C);//returns true
C.isPrototypeOf(A);//returns false

In the above code, I do not understand the reason why I was false in C.isPrototypeOf(A);

+4
source share
2 answers
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
+13
source

C"descends" from B, which "descends" from A. How Ccould it be a prototype A?

Since Cit ultimately inherits from A, but Areceives nothing from C, it is not true that " Cis a prototype A"

+3
source

All Articles