The previous article has introduced the combination of inheritance, and now we will talk about the remaining several inheritance.
prototype Inheritance
Call a function to receive the object returned by the function, and the object's prototype is the parameter object passed in to the function.
Such as:
function personobject (o) { function F () {} = o; return New F ();} var person = { name:"Nicholas", friends:["Shelby", "Court", "Van"]} var person_one = personobject (person);
From the code above, we know that person is the prototype of Person_one. ES5 added a method to normalize the stereotype inheritance, this method is Object.create (), this method has two parameters, the first is as a new object prototype object, like the person above, and the second is to define additional properties for the new object. The second parameter is optional.
Such as:
var Person_one = object.create (person, { name: { value:"Jon" }});
You can use prototype inheritance when you want only one object to remain similar to another object.
Parasitic inheritance
Implement a prototype inheritance in a function, and then add your own properties and methods for the object you receive.
Such as:
function createanother (o) { var person_one = personobject (o); function () { alert ("HI"); } return Person_one;}
Parasitic combined inheritance
Combinatorial inheritance also has its drawbacks, it implements two property inheritance, and parasitic combined inheritance avoids this problem. Instances inherit properties through constructors, whereas prototypes are inherited by means of parasitic inheritance.
Such as:
function inherit (subtype, supertype) { var prototype = Object (supertype.prototype); = subtype; = prototype;}
By invoking the above function, the prototype of the implementation Subtye.prototype is Supertype.prototype, which completes the inheritance of the prototype method.
JavaScript about inheritance