Last active
December 15, 2017 03:01
-
-
Save outoftime/bc859935b976665a82aefcab470a29f7 to your computer and use it in GitHub Desktop.
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
function makeMakeEvaluateExpression() { | |
function makeEvaluateExpression(evalInContext) { | |
return function(expr) { | |
return evalInContext( | |
`({ | |
next: makeEvaluateExpression(function(expr) { return eval(expr); }), | |
value: eval(${JSON.stringify(expr)}) | |
})`, | |
); | |
}; | |
} | |
return makeEvaluateExpression(expr => eval(expr)); | |
} | |
let next = makeMakeEvaluateExpression(); | |
let value; | |
({next, value} = next('var i = 1;')); | |
({next, value} = next('i * 2')); | |
console.log(value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment