The object mentioned above is a function created, and a function is an object. An object is a collection of properties, and there is no method.
Each function has an attribute--prototype.
The property value of this prototype is an object (a collection of attributes), which, by default, has a constructor attribute pointing to the function itself.
, Supertype is a function that has a prototype property whose property value is an object, which has a constructor property by default, and the property value of the property points to the function itself.
For example, Supertype is a function, and the right-hand box is its prototype.
The prototype acts as an object, a collection of properties, a constructor property by default, and some other properties. For example, there are several other properties in the prototype of object.
You can also add your own properties to the prototype of your own custom method.
1 function Fn () {}; 2 fn.prototype.name= ' Zhang San '; 3 fn.prototype.getyear=function () {4 return 1988; 5 };
From the drawing structure, you can see that the Name property and the GetYear method that you manually added are added to the prototype prototype. And look at the following example
1 function Fn () {}; 2 fn.prototype.name= ' Zhang San '; 3 fn.prototype.getyear=function () {4 return 1988; 5 }; 6 var fn=New fn (); 7 Console.log (fn.name); 8 Console.log (Fn.getyear ());
FN is a function, and the FN object is from the FN function new, so that the FN object can invoke the properties and methods in Fn.prototype.
Each object has a hidden property--_proto_, which references the prototype that created the function, fn._proto_ = = = Fn.prototype
The _proto_ here is called an implicit prototype of the object.
In-depth understanding of JavaScript prototypes and Closures (3)--prototype prototypes