Skip to content

Instantly share code, notes, and snippets.

@bartschuller
Created January 3, 2011 21:14
Show Gist options
  • Save bartschuller/763975 to your computer and use it in GitHub Desktop.
Save bartschuller/763975 to your computer and use it in GitHub Desktop.
Example of how to eval and then eval some more, adding to the scope of the first eval.
var evaluatorString =
'(function(stuff) {'+
' return eval("(function() {"'+
'+stuff+'+
'"return "+evaluatorString+";'+
'})();");'+
'})';
var scope1 = eval(evaluatorString);
var scope2 = scope1('var myVar = 42;');
var scope3 = scope2('console.log(myVar); myVar = myVar * 2;');
scope3("console.log(myVar);");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment