The correctness of this paper has to be discussed, the Master passing please feel freeOnly objects in 1.js, including objects, functions, constants, and so on.
object is not explained. Functions also have attributes, one common is prototype. Constants also have properties:
(3). __proto__; // Number {}
2. Prototype of functions
A function is a special object that can execute its own code directly through parentheses.
The function also has a special property, prototype, which is also an object.
The prototype object also has a special property constructor, which is pointed at the beginning of the function.
That is, when JS is interpreted to the function keyword, two objects are created, one is the function itself, and the other is the prototype object. The prototype property of the function object is also pointed to prototype, and the constructor property of the prototype object points to the function object.
3. __proto__ properties of an object
Each object has a __proto__ property (which may not be given directly in the low version of IE), which is very special, because JS iterates through the object itself, the object's __proto__, and the object's __proto__ __ when invoking the object's method or accessing the object's properties. Proto__ ...
The key to the inheritance of the prototype chain
4.new keywords
The new keyword is used to create a method from a function.
In fact, it mainly completes three jobs
- Create an Object
- Point the __proto__ of the object to the prototype of the function
- Call this function (note that the scope of the function is the first step of the new object)
The object can be returned at the end. You can replace it with the following code
function New (F,args) {var a= {};a.__proto__ = f.prototype;f.apply (A,args); return A;}
5.js Object diagram
Where: Xfunction is a custom function, Xprototype is the prototype of Xfunction, Xobject=new xfunction ()
Object is JS built-in Object;_prototype_ is the prototype of object
Empty is the __proto__ of all function objects, is a special function, no prototype,
Hope that we can discuss together, give guidance