JS: 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 object's parent change, all the object's children properties also change, due to Prototype and Inheritance .