+ 1

What method to use besides eval() on calculator

I just stumbled upon a Q&A forum and one of the comments their is don't use eval() because it makes the browser slower and other consequences. What should I use instead?

3rd Sep 2018, 12:14 PM
Brad Baldwin A. Baguyo
Brad Baldwin A. Baguyo - avatar
8 Antworten
+ 1
You should implement your own function to evaluate expressions.
3rd Sep 2018, 12:17 PM
michal
+ 1
Using eval, the browser will be slower, but not for all (slower mostly for drawings). And eval is the best solution for creating a calculator!
3rd Sep 2018, 12:18 PM
Théophile
Théophile - avatar
+ 1
michal , your answer gives me an idea. Thanks
3rd Sep 2018, 12:20 PM
Brad Baldwin A. Baguyo
Brad Baldwin A. Baguyo - avatar
+ 1
Writing your own function isn't something easy : there are lot of conditions, and it can become as slower as the eval function...
3rd Sep 2018, 12:30 PM
Théophile
Théophile - avatar
+ 1
Théophile what do you propose to use?
3rd Sep 2018, 12:31 PM
Brad Baldwin A. Baguyo
Brad Baldwin A. Baguyo - avatar
+ 1
Just use eval... No idea. I'm looking for something else in internet. If I find something, I tell you.
3rd Sep 2018, 12:32 PM
Théophile
Théophile - avatar
+ 1
The problem with eval is that a malicious user might input some bad code and let it evaluate.
3rd Sep 2018, 12:35 PM
michal
+ 1
So, Is there an other function that works like eval?
3rd Sep 2018, 12:38 PM
Théophile
Théophile - avatar