JavaScript: Object.prototype.isPrototypeOf
root.isPrototypeOf(branch)
-
Return
true
if root is in Prototype Chain of branch. Elsefalse
.If root is branch, return
false
// example of isPrototypeOf const j1 = { "j1k": 1 }; const j2 = { "j2k": 1 }; Object.setPrototypeOf(j2, j1); console.log(j1.isPrototypeOf(j2));
// isPrototypeOf returns true for grand parents too const t1 = {}; const t2 = Object.create(t1); const t3 = Object.create(t2); const t4 = Object.create(t3); console.log(t1.isPrototypeOf(t4));
// example of isPrototypeOf on same objects const tt = {}; console.log(tt.isPrototypeOf(tt) === false);
JavaScript Object and Inheritance
- Object Basics
- Object Overview
- Object Type
- Test If a Value is Object Type ð
- Find Object's Type
- Prototype and Inheritance
- Prototype Chain
- Is in Prototype Chain?
- Get/Set Parent
- Show Parent Chain ð
- Create Object
- Object Literal Expr
- Create Object + Parent
- Prevent Adding Property
- Clone Object ð
- Test Object Equality ð
- Add Method to Prototype