Skip to content

Instantly share code, notes, and snippets.

@danott
Created October 28, 2013 22:24
Show Gist options
  • Save danott/7205901 to your computer and use it in GitHub Desktop.
Save danott/7205901 to your computer and use it in GitHub Desktop.
I want to yell at my future self to not manually set read-only properties. Would anyone else benefit from me implementing some kind of read only accessor in Batman.Object?
# Idea
class Whatever extends Batman.Object
@readOnlyAccessor 'computedValue', ->
@get('otherValue') + 2
# Equivalent
class Whatever extends Batman.Object
@accessor 'computedValue',
get: ->
@get('otherValue') + 2
set: (key, value) ->
throw new Error("Duder! Don't do that! #{key} is a read only accessor")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment