Created
March 3, 2015 09:24
-
-
Save shinout/9820012b70c215022168 to your computer and use it in GitHub Desktop.
copying class 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
copyClass = (klass) -> | |
newKlass = (new Function(""" | |
return function (call) { | |
return function #{klass.name}() { | |
return call(this, arguments) | |
}; | |
}; | |
""")())(Function.apply.bind(klass)) | |
for own key, value of klass | |
newKlass[key] = value | |
F = -> | |
F.prototype = klass.prototype | |
newKlass.prototype = new F() | |
return newKlass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see
https://github.com/shinout/copy-class