From the new
MDN docs it says:
The new keyword does the following things:
- Creates a blank, plain JavaScript object.
- Adds a property to the new object (
__proto__
) that links to the constructor function's prototype object
How exactly is the prototype defined then? My thought was it would be:
- If it's in a function (not using the
class
keyword), it would lookup to find if there is a[Constructor].prototype
declared somewhere and use that, and if not it would fallback to...(not sure?). As an example if the constructor is namedRange
it would lookup to see ifRange.prototype
is defined and use that as the prototype. - If it's in a
class
then it would use every method or property to build the prototype up.
Is that more-or-less a correct understanding, or what might I be missing?