Object.create()

The Object.create() method creates a new object, using an existing object to provide the newly created object's __proto__ . (see browser console for visual evidence.)

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Syntax

Object.create(proto[, propertiesObject])

Parameters

proto

The object which should be the prototype of the newly-created object.

propertiesObject

Optional. If specified and not undefined, an object whose enumerable own properties (that is, those properties defined upon itself and not enumerable properties along its prototype chain) specify property descriptors to be added to the newly-created object, with the corresponding property names. These properties correspond to the second argument of Object.defineProperties().

Return value

A new object with the specified prototype object and properties.

Exceptions

A TypeError exception if the propertiesObject parameter isn't null or a non-primitive-wrapper object.

Examples

Classical inheritance with Object.create()

Below is an example of how to use Object.create() to achieve classical inheritance. This is for single inheritance, which is all that JavaScript supports.

Object.assign copies properties from the OtherSuperClass prototype to the MyClass prototype, making them available to all instances of MyClass. Object.assign was introduced with ES2015 and can be polyfilled. If support for older browsers is necessary, jQuery.extend() or _.assign() can be used.