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="btn">Print Info</button>
<div id="cont"></div>
</body>
<script src="itsabuild-min.js"></script>
<script>
var container = document.getElement('#cont'),
A, B, C, D, d;
A = ITSA.Classes.createClass(
function(x) {
this.x = x;
this.rendered = true;
},
{
getInfo: function() {
return 'I am Class A, x='+this.x+', y='+this.y+', rendered='+this.rendered;
}
}
);
B = A.subClass(
function(x, y) {
// the constructor automaticly invoke its superclass with all arguments.
// however, we are going to overrule and invoke it without arguments
// which will lead into NO x-value set
this.$superProp('constructor');
this.y = y;
},
{
getInfo: function() {
return 'I am Class B';
}
},
false
);
C = B.subClass({
getInfo: function() {
return this.$super.$superProp('getInfo');
}
}
);
D = C.subClass();
d = new D(10, 20);
ITSA.Event.after('tap', function(e) {
container.setHTML(d.getInfo());
}, '#btn');
</script>