JavaScript: Object.prototype.isPrototypeOf

By Xah Lee. Date: . Last updated: .
Return true if a is in prototype chain of b. (if a is b, return false).

[see Prototype and Inheritance]

// example of using isPrototypeOf() method
const t1 = {"a":1};
const t2 = Object.create(t1);    // t2's parent is t1
console.log( t1.isPrototypeOf(t2) ); // true
console.log( t1 === Reflect.getPrototypeOf(t2) ); // true
// .isPrototypeOf() returns true for grand parents too

const t1 = {};                    // you
const t2 = Object.create(t1);    // child of t1
const t3 = Object.create(t2);    // grand child of t1
const t4 = Object.create(t3);    // great grand child of t1

console.log( t1.isPrototypeOf(t4) ); // true
const tt = {};
console.log( tt.isPrototypeOf(tt) ); // false

JavaScript Object and Inheritance

∑ JS in Depth

JS in Depth

JS Obj Reference


JS Obj Reference

Object Object