Function objects have the prototype explicit attribute. Instance objects have the __proto__ implicit prototype attribute

For example, in the newly created HTML, there is no Object instance Object, but there is an Object function Object, then this Object has the explicit prototype attribute. Object. Prototype = __proto__ = true;

	// Create a Function(){} Function object
	function Fn(){
		console.log("I am Fn");
	};
	// construct an instance of Function, fn
	var fn = new Fn();
	// Fn. Prototype === Fn. __proto__
	console.log(Fn.prototype === fn.__proto__);/ / return true
	
Copy the code

The prototype of Fn points to an empty Object. Since it is called an empty Object rather than an Object function, it is an instance Object created by the system itself. According to the beginning of the article, the system has a built-in Object function Object. So the __proto__ implicit stereotype property of the empty Object is now equal to the prototype explicit stereotype property of the built-in Object function

	// Create a Function(){} Function object
	function Fn(){
		console.log("I am Fn");
	};
	// construct an instance of Function, fn
	var fn = new Fn();
	// Fn. Prototype === Fn. __proto__
	console.log(Fn.prototype === fn.__proto__);/ / return true

	//Fn.prototype.__proto__ === Object.prototype
	console.log(Fn.prototype.__proto__ === Object.prototype);// still returns true

    // fn.prototype. __proto__ and object. prototype both point to the end of the prototype chain,
    // Is the prototype Object of Object, which is an instance Object and therefore also has a __proto__ attribute with a null value
Copy the code

The properties of a function will be searched in the function itself first, if not, then follow the prototype chain to the prototype Object, and if not, then go to the prototype Object of Object. The properties in the prototype Object of each function Object (Object empty Object) may be different, but all above are the prototype Object of Object. It defines methods like toString, which is why you can use them in the first place. Return undefined if neither attribute is found. (1) Since we all share the end of the prototype chain, does changing the value of one function affect other functions, such as toString?

B station is still silicon Valley course screenshotsThe advanced constructor can be written as function Xxx(){}; Var Xxx = new function () {} var Xxx = new function ()So any Function can be treated as an instance object of the Function constructorFunction. Prototype New Function() : the last parameter is the body of the Function(string);

	// The last argument is the function's body, of type string;
	// All the preceding arguments are required to construct the function argument (name).
	var myFunction = new Function('users'.'salary'.'return users * salary');
Copy the code

For example, function Xxx(){}

	function Fx(){
        console.log('1')}// var Fx = function(){
    // console.log("2")
    // }
    // var Fx = new Function("console.log('3')");
    Fx();/ / returns 1
Copy the code

Var Xxx = function () {} for example

	// function Fx(){
    // console.log('1')
    // }
    var Fx = function(){
        console.log("2")}// var Fx = new Function("console.log('3')");
    Fx();/ / return 2
Copy the code

Var Xxx = new Function() for example

    // function Fx(){
    // console.log('1')
    // }
    // var Fx = function(){
    // console.log("2")
    // }
    var Fx = new Function("console.log('3')");
    Fx();/ / return 3
Copy the code

Var Object = new Function (); var Object = new Function (); Function (prototype); Function (prototype); Function (prototype); Function (prototype); The prototype explicit property corresponds to this.

Function () = new Function (); Function () = new Function (); Function’s __proto__ implicit prototype attribute points to function. prototype and vice versa.So functions are generated by new Function, so all functions have the same implicit prototype, __proto__ is the same, and are function.prorotype