JavaScript: Get/Set Prototype
Get Parent
You can use the following to get a object's parent:
- Reflect.getPrototypeOf → best way.
- Object.getPrototypeOf → implicitly convert arg to object type if not already.
- Object.prototype.__proto__ → hack. Not always work.
Set Parent
- Reflect.setPrototypeOf → best way.
- Object.setPrototypeOf → implicitly convert arg to object type if not already.
- Object.prototype.__proto__ → hack. Not always work.
WARNING: when you change a object X's parent, all X's children will be effected for property lookup, due to the Prototype Chain.
JavaScript: Get/Set Prototype
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