All newly created objects (with the exception of objects created using Object.create(null)) contain the object Object.prototype in their prototype chain. These newly created objects can call newObject.toString() because toString is defined on Object.prototype.
However, the internal prototype of Object is said to be null. If that's the case, why the heck can I do this:
Object.toString(); // prints: "function Object() { [native code] }"
Perhaps I've answered my own question. Is toString also defined on the Object constructor function?
Why?!
Functions don't have to exist in an object's prototype to be invokable on an object.
Given a simple example...
x = {} x.y = function () { } y is not in x's prototype, yet I can use x.y().
No comments:
Post a Comment