thanks to wonderful responses to this question I understand how to call javascript functions with varargs.
now I\'m looking to use apply with a constructor
You could use apply and pass an empty object as the this
argument:
var mid_parser = {};
Parser.apply(mid_parser, mid_patterns);
But that solution will not take care about the prototype chain.
You could create a Parser
object, using the new
operator, but without passing arguments, and then use apply
to re-run the constructor function:
var mid_parser = new Parser();
Parser.apply(mid_parser, mid_patterns);