what is inheritance? A: others give you white process is called inheritance.
//
var inheriting objects parent={
name:
"baba" say: the function () {
alert (" I am baba ");

}}
function proInherit (obj) {
the function F () {}
F.p rototype=obj;
return new F ();
}

the F () for a temporary empty constructor, then the prototype of the F () is set to the parent object, but at the same time it through benefit from _proto_ links with his father all the function object.
//superclass constructor
function Parent () {
this. Name="baba";
}

//superclass prototype method. The Parent prototype. The getName=function () {
return this. The name;
}
var classInherit=(function () {
var F=function () {}
the return function (P, C) {
F.p rototype=P.p rototype.
C.p rototype=new F ()
C.p rototype) constructor=C
}
} ());

  Analyse the method:

//copy inheritance function copyInherit (p, c) {
var I,
toStr=Object. The prototype. ToString,
astr="[Object Array]";
c=c | | {};
the for (I in p) {
if (p.h asOwnProperty (I)) {
if (typeof p==="object" [I]) {
c=toStr. [I] call (p [I])==astr? [] : {}; [I]
c=copy (p [I], c [I]);

} else {
c=p [I] [I];

}}
}
return c;
}

  Analysis of copyInherit (p, c)

when a value gives a variable, divided into preach value and the reference in two ways, when you are within the parent object attribute contains an array type or object type,   [I]=c toStr. Call (p [I])==astr? [] : {}; It will avoid modify the child object properties caused by the parent object attributes have been tampered with.

:

class inheritance is common, because everyone is familiar with this style of the constructor, but have a larger memory footprint. And the original type of inheritance, the relatively small footprint, but contains array, cloning or the type of an object more troublesome. Copying simple inheritance, and applied widely.

 


This concludes the body part