Created
October 28, 2013 22:24
-
-
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?
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
# 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