After spending a few weeks poring over tutorials, I've finally uncovered an interesting fact. When using the prototype property on a constructor function, the key/value pairs on that prototype property are actually copied to the proto property of the newly created object.
function F(){};
F.prototype.k = "v";
console.dir(F.k)//result: "undefined"
console.dir(F.prototype.k)//result: "v"
var o = new F;
console.dir(o.k)//result: "v"
Essentially, the key "k" from the prototype property in the constructor is transferred to the proto property of the newly created object "o," allowing it to be accessed as if it were a regular key/value pair in the object. It's starting to make sense to me now... But then I began to think about how I've seen people use the new keyword with built-in objects like String (even though it's not commonly done).
var s = new String;
The example above illustrates creating a new string item in the same way objects are instantiated from constructor functions. This got me wondering – is String simply a constructor function? To test this theory, I ran:
console.dir(String.prototype)
The result showed a list of properties identical to those attached to variable s. So, could "String" just be a constructor function at its core? This same behavior seems to hold true for other items as well:
console.dir(String.prototype);
console.dir(Number.prototype);
console.dir(Boolean.prototype);
console.dir(Array.prototype);
console.dir(Object.prototype);
console.dir(Function.prototype);
console.dir(Date.prototype);
All these built-in items seem to function in the same way as constructor functions, complete with capitalized names instead of camel case. Could they all just be constructor functions with some additional built-in features?