Object setPrototypeOf() method

Find all information about the JavaScript setPrototypeOf() method of the Object object

Set the prototype of the object.

When you are here, please refer to my guideJavaScript prototypal inheritance

Two parameters are accepted: object and prototype.


Object.setPrototypeOf(object, prototype)


const Animal = {}
Animal.isAnimal = true

const Mammal = Object.create(Animal) Mammal.isMammal = true

console.log(’-------’) Mammal.isAnimal //true const dog = Object.create(Animal)

dog.isAnimal //true console.log(dog.isMammal) //undefined Object.setPrototypeOf(dog, Mammal)

console.log(dog.isAnimal) //true console.log(dog.isMammal) //true

Download mine for freeJavaScript beginner's manual

More js tutorials: