Skip to content

Instantly share code, notes, and snippets.

@jaz303
Created June 28, 2012 18:05
Show Gist options
  • Save jaz303/3012965 to your computer and use it in GitHub Desktop.
Save jaz303/3012965 to your computer and use it in GitHub Desktop.
// trying to do this:
var fn = new Function("foo", "bar", "baz", "return foo + bar + baz;");
// with arbitrary number of args:
var args = ["foo", "bar", "baz"];
var src = "return foo + bar + baz;"
// with a non-ctor fn i'd do:
var allArgs = args.slice(0);
allArgs.push(src);
Function.apply(null, allArgs);
// but can something similar be done with a constructor?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment