Skip to content

Instantly share code, notes, and snippets.

@stephank
Created August 24, 2010 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephank/548059 to your computer and use it in GitHub Desktop.
Save stephank/548059 to your computer and use it in GitHub Desktop.
# 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