Before I was in the prototype chain of JavaScript, prototype inheritance and identifier lookup were somewhat confusing,
For example, the following code:
Copy Code code as follows:
function Foo () {};
var foo = new Foo ();
Foo.prototype.label = "Laruence";
alert (Foo.label); Output:laruence
alert (Foo.label);//output:undefined
Today we see the following figure:
Javascript Object Layout
Also, in JavaScript Object hierarchy see:
The prototype is only used for properties inherited by Objects/instances created by that function. The function itself does not with the associated prototype.
In other words, the prototype of the function object does not work in the prototype chain lookup process,
Today in Firefox found (because Firefox through the __proto__ exposed [[[prototype]]), the real participation identifier lookup is the function object's __proto__,
Copy Code code as follows:
function Foo () {};
var foo = new Foo ();
Foo.__proto__.label = "Laruence";
alert (Foo.label); Output:laruence
alert (Foo.label);//output:undefined
And, apparently:
Copy Code code as follows:
function Foo () {};
Alert (foo.__proto__ = = Foo.prototype); Output:false
In addition, it was explained that
Copy Code code as follows:
alert (Object.foreach); Undefined
Function.prototype.forEach = Function (object, block, context) {
for (var key in object) {
if (typeof this.prototype[key] = = "undefined") {
Block.call (context, Object[key], key, object);
}
}
};
alert (Object.foreach);
alert (Function.foreach);
Alert (Object.foreach = = Function.foreach); True