Created
July 3, 2011 21:18
-
-
Save francescoagati/1062614 to your computer and use it in GitHub Desktop.
getter and setter with closure in coffeescript style attr_accessor of ruby
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
#this version don't work with prototype chain for generation variable prop_value with closure | |
Object::attr_accessor= (prop) -> | |
self=@ | |
do -> | |
prop_value=null | |
self[prop]=(value) -> | |
prop_value=value if value? | |
prop_value | |
Player={} | |
Player.attr_accessor("name") | |
Player.name("mario") | |
alert Player.name() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment