Last active
August 29, 2015 14:04
-
-
Save dejanr/d9adbd409b766b726cb9 to your computer and use it in GitHub Desktop.
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
| /** | |
| * 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]) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)