In this example we will demonstrate the use of single inheritance. First we will create a class called Biped that has a name and a walk method.
xclass.declare("Biped", XObject, {
constructor: function(name) {
console.log("constructing Biped " + name);
this.name = name;
},
walk: function() {
console.log("This " + this.name + " is walking!");
}
});
Next we create a class called Bird that extends Biped and adds a fly method.
xclass.declare("Bird", Biped, {
constructor: function(name) {
console.log("constructing Bird " + name);
},
fly: function() {
console.log("This " + this.name + " is flying!");
}
});
Next we create a class called AquaticBird that extends Bird and adds a swim method.
xclass.declare("AquaticBird", Bird, {
constructor: function(name) {
console.log("constructing AquaticBird " + name);
},
swim: function() {
console.log("This " + this.name + " is swimming!");
}
});
Next we will use the classes we've defined.