JS Built-ins
← Object115 / 150
ObjectObject.setPrototypeOfbeginner

Object.setPrototypeOf() β€” returns the object

πŸ“– 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() β€” return value

Object.setPrototypeOf(obj, proto) returns the modified object itself, enabling chaining.

Challenge: Verify that Object.setPrototypeOf() returns the same object reference.

πŸ’‘ Hints (1)
  • β€’ setPrototypeOf returns the object for convenient chaining