only objects in the 1.js, including objects, functions, constants, and so on.
Object without explanation. Functions also have properties, one of the common is prototype. Constants also have attributes:
(3). __proto__;//number {}
2. Prototype of function
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 points to the function at the beginning.
That is, when JS interprets the function keyword, it creates two objects, one for the function itself and one for 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 Objects
Each object has a __proto__ attribute (which may not be directly given in a lower version of IE), which is very special, because when calling the object's method or accessing the object's properties, JS iterates through the object itself, the object's __proto__, the object's __proto__ __ Proto__ ...
Which is the key to the prototype chain inheritance.
4.new Keywords
The new keyword is used to create a method from a function.
In fact, it basically completes three jobs
- Create an Object
- To point the object's __proto__ to the prototype of the function
- Call this function (at this point, note that the scope of the function is the first step of the new object)
Finally, you can return the object. 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, without prototype,