Created
November 1, 2011 10:34
-
-
Save jacob414/1330277 to your computer and use it in GitHub Desktop.
Class factory in CoffeeScript
This file contains hidden or 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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The point is that the class name and some of the behaviour is are dynamic parameters, not symbols in the code.