Study on the Relationship between the Function and Object have problems of

Article explains, is a front-end bloggers white, the film article is a blogger encountered in the learning process in doubt, according to the information to find, after the draw personal conclusions, the paper if something goes wrong, please correct me.

------- road ahead will be long Come happiness and earth, and the party of mutual encouragement --------

 

js problem in the Function and Object

First understand the concept prototype, called the prototype, in fact, is the essence of an object, since it is the nature of the object, then that is a prototype of the object itself,

(Note: This is the author's own personal understanding, like a prototype mold, through imagination, when an instance of an object is created, the first is to produce a mold from the original object constructor and then, based on this we begin our mold individual processing, the mold of this more in line with our requirements, and finally, after processing is completed, is based on a prototype to produce the final object is instantiated)

So we come to a conclusion: each function will have a prototype property that every function prototype to have an object. (As distinguished from ordinary constructor function is whether the first letter capitalized difference)

 

    console.log(Object instanceof Object);  //true
    console.log(Object.prototype instanceof Object); // false

Since Pangu, js is not there in the Object, but Object.prototype. js in everything (except the original value) are inherited from Object, with the exception of a target exception, that is Object.prototype.

This passage is taken from https://bbs.csdn.net/topics/390772104 , the details can take a look, here I generally say something,

First Look

1     console.log(Object instanceof Object);  //true
2     console.log(Object.prototype instanceof Object); // false

 

 

The results returned by the above code, we can first determine a thing, that is, an example is not the object of Object.prototype

Well, then we went to see

Object.getPrototypeOf(Object) === Function.prototype   //全等哦 true
​
Object.getPrototypeOf(Function.prototype) === Object.prototype  //全等哦 true
​
console.log(Object.getPrototypeOf(Object) === Object.getPrototypeOf(Function));  //全等哦 true

 

  

The code above results illustrate, Function and Object prototype is actually the same.

Flowchart roughly as follows:

 

Pseudo code is substantially, meaning create element operation is to use the given object as a new object prototyping

  

var ObjectPrototype = Create ();    // epoch 
 
var FunctionPrototype = Create (ObjectPrototype);   
 @ FunctionPrototype (after the assignment to the Function.prototype) is of type Object
 // because the prototype is ObjectPrototype 
 
var Function = Create (FunctionPrototype); 
 
Function.prototype = FunctionPrototype;
  // Function Function type is also of type Object
 // implication, and there Function.prototype Object.prototype the object prototype chain Function 
 
Object =   Create (FunctionPrototype); 
 
Object.prototype = ObjectPrototype;
  // Object types are Function, also of type Object
 //The implication on the Object object prototype chain and has Function.prototype Object.prototype

 

The above and to FIG pseudocode summarize, using initially create () constructed ObjectPrototype, then constructed using ObjectPrototype FunctionPrototype, then constructed using FunctionPrototype two most important functions of the objects, and finally ObjectPrototype point Object.prototype. FunctionPrototype point Function.prototype. So far, constitute a strange cycle.

 

In order to better understand the relationship between the Function and Object, I'm from another article, find additional knowledge. The following self-reference links: https://www.jianshu.com/p/5f57dd643bfd

 

 

Guess you like

Origin www.cnblogs.com/zidong/p/11411693.html