Probably the least understood part of JavaScript, standing beside the prototype chain.
So the question is: how does…
new dataObj(args);
…actually create an object, and define its prototype chain/constructors/etc?
Best is to show an alternative, to fully understand this keyword.
The
newoperator uses the internal[[Construct]]method, and it basically does the following:[[Prototype]]of this object, pointing to the Functionprototypeproperty.prototypeproperty is not an object (a primitive values, such as a Number, String, Boolean, Undefined or Null),Object.prototypeis used instead.thisvalue.An equivalent implementation of what the
newoperator does, can be expressed like this (assuming that the ECMAScript 5Object.createmethod is available):