Created
November 28, 2011 13:14
-
-
Save jed/1400363 to your computer and use it in GitHub Desktop.
an attempt to make the new operator dynamically invokeable
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
// usage: newOperator(constructor, [arg1, arg2, ...]) | |
// example: newOperator(Date, [1995, 11, 24]) | |
// => should be identical to new Date(1995, 11, 24) | |
function newOperator(constructor, args) { | |
var i = args.length + 1 | |
, params = [] | |
, fn | |
while (i--) params[i] = "$" + i | |
params.push("return new $0(" + params.slice(1) + ")") | |
fn = Function.apply(null, params) | |
params = params.concat.apply(constructor, args) | |
return fn.apply(null, params) | |
} |
uh .. wait, I know what you mean ... so yes, minus tilde then, updated :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
well, the initial trick does not solve a thing here ... if you want to screw up functions that would work even with native arrays methods ...