Created
May 22, 2012 10:13
-
-
Save melvynhills/2768142 to your computer and use it in GitHub Desktop.
Getter/setter and private variables in CoffeeScript
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 Foo | |
_myPrivateVar = "foo bar" | |
@:: __defineGetter__ "myVar", -> | |
_myPrivateVar | |
@:: __defineSetter__ "myVar", (value) -> | |
_myPrivateVar = value | |
foo = new Foo | |
console.log foo._myPrivateVar # undefined | |
console.log foo.myVar # foo bar | |
foo.myVar = "baz qux" | |
console.log foo.myVar # baz qux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment