Search code examples
javascriptjavascript-objectsprototype

What are the differences between the resutls of Dog.prototype = Object.create(Animal.prototype) and Dog.prototype = {...Animal.prototype}?


What are the differences between the resutls of Dog.prototype = Object.create(Animal.prototype) and Dog.prototype = {...Animal.prototype} ?


Solution

  • There are several differences, including:

    • {...Animal.prototype} will create a separate prototype that lives its own life, unaware of property assignments that might be brought to Animal.prototype

    • {...Animal.prototype} only copies enumerable properties, and as some methods might not be, you'll miss out on them.