Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 12, 2010 18:57
Show Gist options
  • Save ryanflorence/398988 to your computer and use it in GitHub Desktop.
Save ryanflorence/398988 to your computer and use it in GitHub Desktop.
var Human = new Class({
initialize: function(name, age){
this.name = name;
this.age = age;
},
isAlive: true,
energy: 1,
eat: function(){
this.energy++;
}
});
// usage
var bob = new Human('Bob Ross', 50);
bob.energy; // 1, from the prototype
bob.eat(); // assigns bobs own energy to 2
bob.energy; // 2, prototype not checked anymore
bob.name; // Bob Ross, nothing to do with prototype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment