I have a set of variables that I'd like to take as input to a function, then define them for use within that function.
For example:
var variables = {
foo: 1,
bar: 2,
};
function doSomething (scope) {
makeLocal(scope); // I'd like something to do this
return foo + bar;
}
doSomething(variables); // should return 3
Does such a thing exist? PHP has a facility to do this called extract, I'm hoping a similar thing exists for JavaScript. I know that I can add attributes to window, but I'd prefer not to pollute my global namespace if possible.
scope.foo + scope.bar?eval()trick, you'd have to do it indoSomething(), otherwise new variables would be in the scope ofmakeLocal().