Apart from eval, is there any other way to instantiate an object using variable argument list?
E.g.: var foo = instantiate(className, [arg1, arg2, ...])
var foo = instantiate(className, [arg1, arg2, ...])
Using Object.create() in ES5:
function instantiate(constructor, args) { var instance = Object.create(constructor.prototype); constructor.apply(instance, args); return instance; }
Using the spread operator in ES6:
var foo = new constructor(...args);