Skip to content

Instantly share code, notes, and snippets.

@dejanr
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save dejanr/d9adbd409b766b726cb9 to your computer and use it in GitHub Desktop.

Select an option

Save dejanr/d9adbd409b766b726cb9 to your computer and use it in GitHub Desktop.
/**
* Construct ctor with passed arguments
*/
function construct(ctor, args) {
var factory = function() {
return ctor.apply(this, args)
}
factory.prototype = ctor.prototype
return new factory()
}
function SomeScene() {
console.log('scene initialized', arguments)
}
construct(SomeScene, [1, 2, 3, 4])
construct(SomeScene, [1, 2])
@dejanr
Copy link
Copy Markdown
Author

dejanr commented Jul 23, 2014

So regarding your use case, you would use it like this , don't forget to splice arguments

var args = [].splice.call(arguments, 0);
construct(ctor, args)

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