A constructor method is a JavaScript function conventionally invoked with new to initialize an object and establish its prototype relationship. The surprising part is that new is not a single opaque operation: it allocates an object, links its prototype, calls the function with this bound to that object, and then examines the return value. section 6.1.1
Reason about construction in this order:
- Allocate an ordinary object. section 6.1.1
- Set its internal [[Prototype]] to the constructor function's prototype property. section 6.1.1
- Call the function with this bound to the fresh object, so assignments such as this.name = value become own properties. section 6.1.1
- Return the fresh object unless the constructor returns another object; primitive returns do not replace it. section 6.1.1
Simulating new
function simulateNew(Constructor, ...args) { const obj = Object.create(Constructor.prototype); const result = Constructor.call(obj, ...args); return result instanceof Object ? result : obj; } function Gadget(name) { this.name = name; } const gadget = simulateNew(Gadget, 'phone'); This decomposition exposes why changing a constructor's prototype affects later instances, while earlier instances retain the prototype selected at creation time. section 6.1.1
Constructor functions also provide an optimization boundary. When properties are assigned in a consistent order, V8 can learn and reuse the resulting object shape; incrementally assembling objects leaves more shape transitions for the engine to discover. section 5.10.1
Class constructors retain the same prototype-based construction model while adding guardrails: classes require new, and class methods are shared through the prototype. new.target distinguishes constructor calls from ordinary calls for function-based APIs. section 6.2.4 section 6.1.2

















