Objective:
JavaScript is object-oriented, and all objects have a prototype chain that belongs to them. object and function may be a lot of look at object instanceof function, function instanceof object is true and confusing, so first look at the object instance.
One, JS in the so-called example
1. such as var a = new A (); This is generally considered "A is an instance object of a function".
2. What is the process of the new operation?
1.new Create an empty object {} called small C
2. Then place the A.prototype at the top of the prototype chain of small c. That small c.__proto__ point to A.prototype
3. Execute a function, point A in this to small C, execute the end, if there is no return then the default return this reference.
Then one of the functions of new is to add A.prototype to the prototype chain of a.
3. Instanceof is the method of judging the example in JS, the basis of judging is (example a instanceof a) determine whether a prototype chain contains A.prototype.
4. An example of a general understanding of new is included in the synthesis. The so-called O is an instance of the FN object, actually refers to the O prototype chain contains Fn.prototype
Two, the fuzzy diagram of object and function (I draw very rubbing)
Explanation: The prototype property of all functions has constructor point to the function.
All objects have a prototype chain (Object.prototype's prototype chain is null).
__proto__ (in Chrome, FF) represents [[Proto]] built-in properties.
After seeing this figure, I should understand why instanceof is the result of that.
Third, the relationship between objects and object, prototype chain end in Object.prototype
The Object.prototype's prototype chain is empty (that is, there is no prototype object). Therefore Object.prototype instanceof Object is false.
Judging type with typeof, typeof (object.prototype) = = = ' object '. So not all objects are instances of object objects. All objects except Object.prototype should be instances of object objects.
I am a beginner welcome to look at the various suggestions, said the wrong place is thanks ...
Reprint Please specify source: http://blog.csdn.net/SyKent
http://blog.csdn.net/sykent/article/details/8003343
Analysis of function and object of "JavaScript" javascript