For example, consider the Number(..) function acting as a constructor, quoting from the ES5.1 spec:15.7.2 The Number Constructor. When Number is called as part of a new expression it is a constructor:it initialises the newly created object. So, pretty much any ol’ function, including the built-in object functions like Number(..) can be called with new in front of it, and that makes that function call a constructor call. This is an important but subtle distinction: there’s really no such thing as “constructor
functions,” but rather construction calls of functions. When a function is invoked with new in front of it, otherwise known as a constructor call, the following things are done automatically:
- A brand new object is created (aka constructed) out of thin air.
- The newly constructed object is [[Prototype]]-linked.
- The newly constructed object is set as the this binding for that function call.
- Unless the function returns its own alternate object, the new invoked function call will automatically return the newly constructed
By calling foo(..) with new in front of it, we’ve constructed a new object and set that new object as the this for the call of foo(..). So new is the final way that a function call’s this can be bound.