Created
September 29, 2013 00:27
-
-
Save francescoagati/6748072 to your computer and use it in GitHub Desktop.
metaprogramming for coffeescript
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
meta = (context,fn) -> | |
def = | |
accessors: (names...) -> @accessor(name) for name in names | |
accessor: (name) -> | |
context["get_#{name}"] = -> @[name] | |
context["set_#{name}"] = (v) -> @[name] = v | |
fn(def) | |
class Pippa | |
meta @::, (def) -> | |
def.accessors 'name','surname' | |
x=(new Pippa) | |
x.set_name('aaaa') | |
x.set_surname('abaaa') | |
alert x.get_surname() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment