Skip to content

Instantly share code, notes, and snippets.

@butchi
Created November 27, 2015 11:10
Show Gist options
  • Save butchi/2d8d1a583999744d9c27 to your computer and use it in GitHub Desktop.
Save butchi/2d8d1a583999744d9c27 to your computer and use it in GitHub Desktop.
Functionによるevalの代替 ref: http://qiita.com/butchi_y/items/d6024f81a9eda826fea0
mathEval("pow(2, 10), alert('あぶない!')")();
function mathEval(expr) {
return Function('return Math.' + expr);
}
var f = mathEval("pow(2, 10);");
var result = f();
console.log(result);
function myEval(expr) {
Function(expr)();
}
myEval("alert('Thanks,'); alert('world!');");
function wrappedEval(expr) {
(function() {
eval(expr);
})();
}
wrappedEval("alert('Thanks,'); alert('world!');");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment