constructor that defines the parent type of all fliers
function Flyer (fname,fspeed) {
This.fname=fname;
This.fspeed=fspeed;
}
Flyer.prototype.fly=function () {//fly placed in Flyer.prototype
Console.log (this.fname+ "to" +this.fspeed+ "speed");
}
Define the first flier: Bee, inheriting and extending the parent type Flyer
Define unique constructors, inherit and extend the flyer constructor
function Bee (fname,fspeed,award) {
Flyer.apply (this,arguments);//1. Methods that hijack another object, inheriting the properties of another object
The second parameter is the one I want to pass to the flyer parameter.
This.award=award; Unique properties:
}
Bee.prototype.get=function () {
Console.log ("Get Properties unique to the object:" +this.award);
}
2. Let the prototype object of the subtype inherit the prototype object of the parent type
Object.setprototypeof (Bee.prototype,flyer.prototype); Equivalent to Bee.__proto__=flyer
var bee = new Bee ("Little Bee", "1 Life");
var flyer = New Flyer ("Bee", "1 Life");
Console.log (flyer);//flyer {fname: "Bee", fspeed:40}
Console.log (BEE); Bee {fname: "Little Bee", Fspeed:30, Award: "1 Life"}
Bee.fly ();
Bee.get ();
Js Apply method Detailed: http://www.360doc.com/content/13/0807/19/13328522_305431575.shtml
Use of the Apply method in JS: http://www.cnblogs.com/delin/archive/2010/06/17/1759695.html
JS implementation of several ways to inherit: http://www.cnblogs.com/humin/p/4556820.html
JS Constructor, prototype inheritance