Inherited
1. Object posing
/* Function ClassA (scolor) {
This.color = Scolor;
This.saycolor = function () {
alert (This.color);
};
}
function ClassB (Scolor, SName) {
This.newmethod = ClassA;
This.newmethod (Scolor);
Delete This.newmethod;
THIS.name = SName;
This.sayname = function () {
alert (this.name);
};
}
var obja = new ClassA ("Blue");
var objb = new ClassB ("Red", "John");
Obja.saycolor (); Output "Blue"
Objb.saycolor (); Output "Red"
Objb.sayname (); Output "John" */
2, call method, A.call (B,...); A, which represents the parent class, B, which represents the child class. The second parameter indicates the argument passed to the parent class
2.1. Add a method to an object
/* function sss (AA) {
alert (AA);
}
var obj=new Object ();
Obj.obj111= "23545";
Sss.call (obj, "yellow");
*/
2.2. Object Inheritance Object
/* Function ClassA (scolor) {
This.color = Scolor;
This.saycolor = function () {
alert (This.color);
};
}
function ClassB (Scolor, SName) {
Classa.call (this, scolor);
THIS.name = SName;
This.sayname = function () {
alert (this.name);
};
}
var clsb=new ClassB ("Blue", "ADFADF");
Clsb.saycolor (); */
3, apply method, A.apply (B,...); A, which represents the parent class, B, which represents the child class. The second parameter represents the arguments passed to the parent class.
parameter is an array type
3.1. How to add Objects
/* Function aaa (AAA) {
Alert ("AAAA" +aaa);
}
var obj=new Object ();
Obj.name= "2343";
Aaa.apply (obj,new Array ("---bbb")); */
3.2. Object Inheritance Object
/* function ClassA (name) {
This.name=name;
This.showname=function () {
alert (this.name);
};
}
function ClassB (name) {
This.nameb=name;
This.aaa=classa;
This.aaa.apply (this,new Array (THIS.NAMEB));
This.showname1=function () {
Alert (this.nameb+ "... bbbbb");
};
}
var bbb=new ClassB ("CCC");
Bbb.showname ();
Bbb.showname1 (); */
JS Object-oriented program settings--Inheritance mechanism