Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created April 20, 2011 03:39
Show Gist options
  • Save robotlolita/930286 to your computer and use it in GitHub Desktop.
Save robotlolita/930286 to your computer and use it in GitHub Desktop.
function Mage(name) {
this.name = name
}
Mage.prototype = function() {
return { cast: cast
, meditate: meditate }
function cast(spell, can) {
if (can) return this.name + " cast " + spell
else return "Nothing happens!"
}
function meditate() {
return "You start meditatin... zzz"
}
}()
inherit(Apprentice, Mage.prototype)
function Apprentice(name) {
upper(this, "constructor", name)
}
extend(Apprentice.prototype, function() {
return { cast: cast }
function cast(spell, can) {
return upper(this, "cast", spell, can || Math.random() < 0.5)
}
}())
inherit(Sorcerer, Apprentice.prototype)
function Sorcerer(name) {
upper(this, "constructor", "Mighty " + name)
}
extend(Sorcerer.prototype, function() {
return { cast: cast }
function cast(spell) {
return upper(this, "cast", spell, true)
}
function meditate() {
return "...Your magic has increased!"
}
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment