1 understanding JavaScript Constructor Implementation Principles
In JavaScript, each function is named "Prototype" and is used to refer to the prototype object. This prototype object is also known as the "constructor" property, which in turn references the function itself. This is a circular reference
2 JavaScript Quest: Constructor Constructor
In addition to creating objects, the constructor (constructor) also does another useful thing--automatically sets the prototype object (prototype objects) for the new object that was created. The prototype object is stored in the Constructorfunction.prototype property.
3 JavaScript inheritance in a detailed way
1) prototype chain inheritance
function Parent () { this.name = ' Mike '; } function Child () { this.age =; } Child.prototype = new parent ();//child inherits the parent, through the prototype, forms the chain var test = new Child (); alert (test.age); alert (test.name);//Get inherited Property}
2) Combination Inheritance
function Parent (age) { this.name = [' Mike ', ' Jack ', ' Smith ']; This.age = age; } Parent.prototype.run = function () { return this.name + ' is both ' + this.age; }; function Child (age) { parent.call (this,age);//object impersonating, giving super type parameter } child.prototype = new Parent ();//prototype chain inheritance var test = new Child (21);//write New Parent (21) also line alert (Test.run ());//mike,jack,smith is both21
Use the prototype chain to implement inheritance of prototype properties and methods, and to implement inheritance of instance properties by borrowing constructors. This enables the reuse of functions both by defining methods on the prototype and ensuring that each instance has its own properties.
4 JavaScript Inheritance Detailed
A series of articles, not read
JavaScript Constructor Learning Notes