This example shows how to inherit Classes. Every master-class should be defined using ITSA.Classes.createClass(). From that point out, Classes can be inherited by using subClass of the parent-Class.
Click on the buttons to make the users speak or be silent.
Code-example:
<body>
<button id="btnMaster">Print Master values</button>
<button id="btnSub">Print Sub values</button>
<button id="btnSubSub">Print SubSub values</button>
<div id="cont"></div>
</body>
<script src="itsabuild-min.js"></script>
<script>
var container = document.getElement('#cont'),
MasterClass, SubClass, SubSubClass, master, sub, subsub;
MasterClass = ITSA.Classes.createClass(
function(x) {
this.x = x;
},
{
printValues: function() {
container.setHTML('values of MasterClass-instance --> x: '+this.x);
}
}
);
SubClass = MasterClass.subClass(
function(x, y) {
// the constructor automaticly invoke its superclass!
this.y = y;
},
{
printValues: function() {
container.setHTML('values of SubClass-instance --> x: '+this.x+', y: '+this.y);
}
}
);
SubSubClass = SubClass.subClass(
function(x, y, z) {
// the constructor automaticly invoke its superclass!
this.z = z;
},
{
printValues: function() {
container.setHTML('values of SubSubClass-instance --> x: '+this.x+', y: '+this.y+', z: '+this.z);
}
}
);
master = new MasterClass(1);
sub = new SubClass(10, 20);
subsub = new SubSubClass(100, 200, 300);
ITSA.Event.after('tap', function(e) {
master.printValues();
}, '#btnMaster');
ITSA.Event.after('tap', function(e) {
sub.printValues();
}, '#btnSub');
ITSA.Event.after('tap', function(e) {
subsub.printValues();
}, '#btnSubSub');
</script>