JS: Object.prototype.isPrototypeOf
objA.isPrototypeOf(objB)-
- Return
trueif objA is in Prototype Chain of objB. Elsefalse. - If objA is objB, return
false
// example of isPrototypeOf const xdad = {}; const xson = {}; // make xdad the parent of xson Object.setPrototypeOf(xson, xdad); console.assert(xdad.isPrototypeOf(xson)); // isPrototypeOf returns true for grand parents too const xgen1 = {}; const xgen2 = Object.create(xgen1); const xgen3 = Object.create(xgen2); const xgen4 = Object.create(xgen3); console.assert(xgen1.isPrototypeOf(xgen4)); // example of isPrototypeOf on same objects const xx = {}; console.log(xx.isPrototypeOf(xx) === false); - Return