Skip to content

Instantly share code, notes, and snippets.

@shinout
Created March 3, 2015 09:24
Show Gist options
  • Save shinout/9820012b70c215022168 to your computer and use it in GitHub Desktop.
Save shinout/9820012b70c215022168 to your computer and use it in GitHub Desktop.
copying class in CoffeeScript
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
@shinout
Copy link
Author

shinout commented Mar 5, 2015

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