Object.create

Creates an object that has the specified prototype or that has null prototype.

Syntax

create(proto, properties?)

Parameters

Return value

A new object with the specified prototype object and properties.

Examples

let vehicle = {
  speed: 10,
  unit: "km/h",
  toString() {
    return `${this.speed} ${this.unit}`
  }
}

let car = Object.create(vehicle, {
  speed: {
    value: 100,
    enumerable: true,
    writable: true,
    configurable: true
  }
})

car.toString()
"100 km/h"