Skip to content

Instantly share code, notes, and snippets.

@outoftime
Last active December 15, 2017 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outoftime/bc859935b976665a82aefcab470a29f7 to your computer and use it in GitHub Desktop.
Save outoftime/bc859935b976665a82aefcab470a29f7 to your computer and use it in GitHub Desktop.
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