JS Built-ins
← Object113 / 150
ObjectObject.setPrototypeOfintermediate

Object.setPrototypeOf() β€” verify with getPrototypeOf

πŸ“– Usage Example
// Set the prototype of an object
const animal = { breathe() { return true } }
const dog = {}
Object.setPrototypeOf(dog, animal)
dog.breathe()   // β†’ true

Use Object.setPrototypeOf() to dynamically change an object's prototype, though creating objects with the correct prototype upfront is preferred.

Object.setPrototypeOf() β€” verification

After calling Object.setPrototypeOf(), use Object.getPrototypeOf() to confirm the prototype was correctly set.

Challenge: Set the prototype and verify it with Object.getPrototypeOf().

πŸ’‘ Hints (1)
  • β€’ Use getPrototypeOf to verify the prototype was set correctly