Mhh, you could use the Function
-constructor:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
function evil(fn) {
return new Function('return ' + fn)();
}
console.log( evil('12/5*9+9.4*2') ); // => 40.4
More Related Contents:
- Why is using the JavaScript eval function a bad idea?
- When is JavaScript’s eval() not evil?
- Executing elements inserted with .innerHTML
- Convert a string to a template string
- Are eval() and new Function() the same thing?
- (1, eval)(‘this’) vs eval(‘this’) in JavaScript?
- Why does JavaScript’s eval need parentheses to eval JSON data?
- Is it possible to achieve dynamic scoping in JavaScript without resorting to eval?
- Why {} + {} is NaN only on the client side? Why not in Node.js?
- Is Javascript eval() so dangerous? [duplicate]
- Specify scope for eval() in JavaScript?
- Eval is evil… So what should I use instead?
- what does eval do and why its evil? [duplicate]
- Safely sandbox and execute user submitted JavaScript?
- Accessing or creating nested JavaScript objects with string key without eval
- Restricting eval() to a narrow scope
- Why the open quote and bracket for eval(‘(‘ + jsonString+ ‘)’) when parsing json string
- What are the Alternatives to eval in JavaScript?
- How to code a calculator in JavaScript without ‘eval’
- Context-preserving eval
- eval javascript, check for syntax error
- Alternatives to JavaScript eval() for parsing JSON
- What’s the main benefit of using eval() in JavaScript?
- Alternative to eval() javascript [duplicate]
- Exploiting JavaScript’s eval() method
- JQuery getJSON – ajax parseerror
- How can I get the index of an object by its property in JavaScript?
- How to get year/month/day from a date object?
- While loop using bluebird promises
- Check if HTML snippet is valid with JavaScript