var Vehicle = function Vehicle() {
// ...
}
var vehicle = new Vehicle();
When new Vehicle() is called, JavaScript does four things:
- It creates a new object.
- It sets the constructor property of the object to Vehicle.
- It sets up the object to delegate to Vehicle.prototype.
- It calls Vehicle() in the context of the new object.
What is that third point telling? Does it mean new object constructor prototype is set to function.prototype? What does delegate mean here?
You just consider delegate as reference, every object has an
[[Prototype]]internal property, and it references to its constructor’s prorotype, so:This is a seudo code about what
newoperator is doing: