Created
November 23, 2011 12:33
-
-
Save thinkphp/1388565 to your computer and use it in GitHub Desktop.
Class.extend Inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Human = Class.extend({ | |
init: function(name) { | |
this.name = name; | |
this.energy = 1; | |
this.isAlive = true; | |
}, | |
eat: function() { | |
this.energy++; | |
} | |
}); | |
var Gibon = Human.extend({ | |
init: function(name) { | |
this._super(name); | |
}, | |
attack: function(target) { | |
target.isAlive = false; | |
this.kills++; | |
}, | |
kills: 0 | |
}); | |
var h = new Human("Adrian"), | |
g = new Gibon("Liviu"); | |
g.attack(h); | |
alert(h.name + ' - '+ h.isAlive); | |
alert(g.name +' kills: ' + g.kills); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment