Skip to content

Instantly share code, notes, and snippets.

@jacob414
Created November 1, 2011 10:34
Show Gist options
  • Save jacob414/1330277 to your computer and use it in GitHub Desktop.
Save jacob414/1330277 to your computer and use it in GitHub Desktop.
Class factory in CoffeeScript
gen = (clsname, val) ->
C = class
C.prototype[val] = -> "#{clsname} says #{val}"
C
Cat = gen 'Cat', 'meow'
console.log Cat
c = new Cat
alert c.meow()
Dog = gen 'Dog', 'woff'
d = new Dog
alert d.woff()
@jacob414
Copy link
Author

jacob414 commented Nov 1, 2011

The point is that the class name and some of the behaviour is are dynamic parameters, not symbols in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment