This article mainly introduces a misunderstanding of the Javascript prototype chain and prototype. If you need it, you can refer to my previous questions about prototype inheritance and identifier search in the Javascript prototype chain,
For example, the following code:
The Code is as follows:
Function Foo (){};
Var foo = new Foo ();
Foo. prototype. label = "laruence ";
Alert (foo. label); // output: laruence
Alert (Foo. label); // output: undefined
The following figure is displayed today:
Javascript object layout
In addition, you can see in Javascript Object Hierarchy:
The prototype is only used for properties inherited by objects/instances created by that function. The function itself does not use the associated prototype.
That is to say, the prototype of the function object does not apply to the search process of the prototype chain,
Today, I found in firefox that (because firefox exposes [[prototype] Through _ proto _), the _ proto __,
The Code is as follows:
Function Foo (){};
Var foo = new Foo ();
Foo. _ proto _. label = "laruence ";
Alert (Foo. label); // output: laruence
Alert (foo. label); // output: undefined
Obviously:
The Code is as follows:
Function Foo (){};
Alert (Foo. _ proto _ = Foo. prototype); // output: false
In addition, it also explains,
The Code is 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