Object.create
Object.create()
returns a new object with a prototype
of the object you passed it.
Inheritance
Results in a prototype chain like:
Which means we can do:
What about the second argument?
The second argument is not too exciting; it works as a convenient shortcut to Object.defineProperties()
. In short Object.defineProperties
allows you to define the properties of particular keys on your object.
I won’t go over the API for Object.defineProperties
in this article, but you can read all about it on our ever trustworthy MDN.