Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Created June 14, 2015 09:57
Show Gist options
  • Save aleclarson/0ca7454bf4c865d79e82 to your computer and use it in GitHub Desktop.
Save aleclarson/0ca7454bf4c865d79e82 to your computer and use it in GitHub Desktop.
applyToNew(constructor, args)

usage

MyConstructor = ->
  this.args = arguments
  this

obj = applyToNew MyConstructor, [1, 2, 3]

obj.args # [ 1, 2, 3 ]
applyToNew = (c, args) ->
new ( c.bind.apply c, [c].concat args )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment