The first two days from the Internet to see a topic, the general content is as follows:
var f=function() {}; Function.prototype.a=function() {Console.log ("a");};o bject.prototype.b=function() {Console.log ("B");}; var f=New f (); f.b (); F.A ();
At first look at this problem, feel very simple, should be output "B" and "a" bar, but actually run, not so, the actual result is: The second function error, did not find a definition. What's going on?
In fact, this topic mainly examines the understanding of the prototype chain. We know that when an object cannot find a property, it will look up in its prototype chain to see if there is a property in the other object, until it is found, if it is not found, then it will be an error like the above topic.
How does the prototype chain build up? In the JS world, everything is object, each object has a private __proto__ attribute, which is used to identify the prototype object above it, so that the entire prototype chain through this property to build up.
And what is the prototype chain in the title? Build the prototype chain from the top of the prototype chain, which is the current object F. We know that the __proto__ property value is actually the prototype property value of the current object constructor, so there is the following equation:
The F.__proto__===f.prototype;//f constructor is the F
F.prototype.__proto__===object.prototype; The F.prototype constructor is an object
Similarly, the summary prototype chain is as follows:
F---->f.prototype---->object.prototype---->nullf---->function.prototype----> Object.prototype---->null
Therefore, it is obvious that F.A does not exist.
My view of JS prototype chain