Javascript Prototypal Inheritance Model (with Examples)

The following are example javascript statements that make use of an object prototype.

const vehicle = { wheels: 4 }


const car = Object.create(vehicle) // fast

Object.setPrototypeOf(car, vehicle) // slow

function vehicle() { this.wheels = 4 }

const car = new vehicle(); // car now has access to car.wheels, which has the value 4

<object>.__proto__ is deprecated and should no longer be used; the best practice is to use Object.getPrototypeOf(object).

vehicle.prototype.value = 0;