Skip to content

Instantly share code, notes, and snippets.

@Maxdamantus
Forked from robotlolita/gist:930286
Created April 20, 2011 03:48
Show Gist options
  • Save Maxdamantus/930295 to your computer and use it in GitHub Desktop.
Save Maxdamantus/930295 to your computer and use it in GitHub Desktop.
function extend(from, to){
var x, r = Object.create(from);
for(x in to)
r[x] = to[x];
return r;
}
function Mage(name) {
this.name = name;
}
Mage.prototype = {
cast: function(spell, can){
return can?
this.name + " cast " + spell :
"Nothing happens!";
},
meditate: function(){
return "You start meditatin... zzz";
}
};
function Apprentice(name) {
Mage(name);
}
Apprentice.prototype = extend(Mage.prototype, {
cast: function(spell, can){
return Mage.prototype.cast.call(this, spell, can || Math.random() < 0.5);
}
});
function Sorcerer(name) {
Apprentice("Mighty " + name);
}
Sorcerer.prototype = extend(Apprentice.prototype, {
cast: function(spell){
return Apprentice.prototype.cast.call(this, spell, true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment