Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save francescoagati/1062614 to your computer and use it in GitHub Desktop.
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 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