Object.create()

ES5+

Creates a new object with the specified prototype object and properties.

Syntax

Object.create(proto, propertiesObject)

Parameters

proto Object | null

The object to be the prototype of the newly created object

propertiesObject Object optional

Object whose enumerable own properties specify property descriptors

Return Value

Object

A new object with the specified prototype and properties

Examples

JavaScript
const person = { greet() { return 'Hello!'; } };
const john = Object.create(person);
john.name = 'John';
console.log(john.greet());
console.log(john.name);
Output:
// 'Hello!' 'John'

Related Methods