Skip to content

Instantly share code, notes, and snippets.

@christopherdebeer
Created August 5, 2013 10:50
Show Gist options
  • Save christopherdebeer/6155033 to your computer and use it in GitHub Desktop.
Save christopherdebeer/6155033 to your computer and use it in GitHub Desktop.
Coffee Class getters and setters
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