Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created June 17, 2011 15:09
Show Gist options
  • Select an option

  • Save juandopazo/1031607 to your computer and use it in GitHub Desktop.

Select an option

Save juandopazo/1031607 to your computer and use it in GitHub Desktop.
class sugar proposal
class Monster {
// Goes on the instance
own name;
// Goes on the instance and is private
// In the lexical context of a member of the class it can be accessed with {{Instance}}.health or {{Instance}}["health"]
private own health = 10;
constructor(name) {
this.name = name;
}
isAlive() {
return this.health <= 0;
}
say(message) {
if (!this.isAlive()) {
message = '...';
}
alert(this.name + ' says: ' + message;
}
wound(damage) {
this.health -= damage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment