Creates an object that has the specified prototype or that has null prototype.
create(proto, properties?)
proto
The object to use as a prototype. May be null.
properties optional
An object that contains one or more property descriptors.
A new object with the specified prototype object and properties.
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"