Created
August 24, 2010 18:33
-
-
Save stephank/548059 to your computer and use it in GitHub Desktop.
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
# Reverse apply. | |
Object::apply = (func, args) -> func.apply this, args | |
# Base model class. | |
class Model | |
has_many: (what) -> | |
@[what] = -> | |
how_many = @["number_of_#{what}"] | |
console.log "I have #{how_many} shiney #{what}!" | |
# An example model. | |
class Foo extends Model | |
Foo::apply -> | |
@has_many 'cars' | |
# Example usage. | |
f = new Foo() | |
f.number_of_cars = 3 | |
f.cars() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment