Last active
December 6, 2016 15:02
-
-
Save halcarleton/06f72f3993bac1837f305c41216cf051 to your computer and use it in GitHub Desktop.
call/apply with `new` operator
This file contains 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
function applyNew(constructor, args) { | |
return new (Function.prototype.bind.apply(constructor, [constructor].concat(args)))(); | |
} | |
function callNew(func /*[, arg1[, arg2[, ...]]]*/) { | |
return applyNew(func, ...arguments); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment