A super class
even though collective thinking states that this is a bad idea.
by Nick Clarkson
JavaScript
var s = function(o){
this.o = o;
this.bind()
this.do('init');
}
s.prototype.bind = function(){
for(opt in this.o) if(!this[opt]) this[opt] = this.o[opt];
};
s.prototype.test = function(what, type){
return typeof what === type;
};
s.prototype.do = function(what){
var w = this.o[what];
if(this.test(w, 'function')) {
w.call(this);
return true;
}
};
s.prototype.rnd = function(m){
this.do('rnd');
return Math.round(Math.random()*( m || 1 ));
};
//////////////////////////////////////////////////
new s({
init: function(){
this.log('init');
this.reset();
this.log(this.rnd(10));
},
reset: function(){
this.log('reset');
},
rnd: function(){
this.log('before rnd');
},
log: function(str){
var li = document.createElement('li');
li.innerHTML = '> ' + str;
document.getElementById('log').appendChild(li);
}
})