Created
August 5, 2013 10:50
-
-
Save christopherdebeer/6155033 to your computer and use it in GitHub Desktop.
Coffee Class getters and setters
This file contains 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 Person | |
get = (props) => | |
@::__defineGetter__ name, func for name, func of props | |
set = (props) => | |
@::__defineSetter__ name, func for name, func of props | |
get age: -> (Date.now() - @birthdate) / MILLIS_PER_YEAR | |
get birthdate: -> @_birthdate | |
set birthdate: (val) -> | |
throw new Error 'Birthdates are immutable.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment