Javascript Object.create()

The Object.create() method creates a new object using the prototype of the given object.

Example


create() Syntax

The syntax of the create() method is:

Object.create(proto, propertiesObject)

The create() method, being a static method, is called using the Object class name.


create() Parameters

The create() method takes in:

  • proto - The object which should be the prototype of the newly-created object.
  • propertiesObject (optional) - An object whose enumerable own properties specify property descriptors to be added to the newly-created object. These properties correspond to the second argument of Object.defineProperties().

create() Return Value

  • Returns a new object with the specified prototype object and properties.

Note: If proto is not null or an Object, TypeError is thrown.


Example: Using Object.create()

Output

Unspecified
Hiss
Hey! I am Jack.

Recommended Reading: Javascript Object isPrototypeOf()