Created
June 17, 2011 15:09
-
-
Save juandopazo/1031607 to your computer and use it in GitHub Desktop.
class sugar proposal
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
| 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