Last active
September 5, 2017 14:59
-
-
Save beeryardtech/14ef8fb243bc9de3605cfecbb6a62209 to your computer and use it in GitHub Desktop.
How to create a dynamic constructor without needing caller to use "new"
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 X(a, b, c) { | |
console.log(a, b, c); | |
} | |
var c = (n, Fn) => { | |
return function() { | |
var a = _.toArray(arguments); | |
var t = _.times(n, (n) => { | |
return 'a[' + n + ']' | |
}); | |
eval('new Fn(' + t.join(', ') + ');'); | |
}; | |
}; | |
c(3, X)('aa', 'bb', 'cc'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment