Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created November 23, 2011 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/1388565 to your computer and use it in GitHub Desktop.
Save thinkphp/1388565 to your computer and use it in GitHub Desktop.
Class.extend Inheritance
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