js's constructor and super

Constructor is specially born for function, it exists in the prototype property of each function, this constructor saves a reference to the function.

When executing the following code   function  F () {  // some code }   , two actions will occur: 1 is to add a prototype property to the function (prototype) 2. An additional constructor property is added to the prototype object, and this property holds a reference to the function F.
In this way, when we use the function F as a custom constructor to create an object, the object instance will automatically save a property proto that points to the interior of its constructor (that is, the custom constructor F),

So we can access all the properties and methods that the constructor's prototype has in each object instance, as if they were the instance's own. Of course, the instance also has a constructor property (obtained from the prototype), each object instance can access its constructor through the constrcutor object, please see the following code:

var f = new F();
alert(f.constructor === F);// output true
alert(f.constructor === F.prototype.constructor);// output true


For specific principles and detailed explanations, please see the reprint address: https://blog.csdn.net/zengyonglan/article/details/53465505

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324920276&siteId=291194637