Created
January 3, 2011 21:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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