Is a function plotter a legitimate use of eval() in JavaScript?
Posted
by
moose
on Programmers
See other posts from Programmers
or by moose
Published on 2013-07-01T08:42:56Z
Indexed on
2013/07/01
10:28 UTC
Read the original article
Hit count: 190
JavaScript
From PHP development I know that eval is evil and I've recently read What constitutes “Proper use” of the javascript Eval feature? and Don't be eval. The only proper use of eval I've read is Ajax.
I'm currently developing a visualization tool that lets users see how polynomials can interpolate functions:
I use eval for evaluation of arbitrary functions. Is this a legitimate use of eval? How could I get rid of eval?
I want the user to be able to execute any function of the following forms:
- a x^i with a,i in R
- sin, cos, tan
- b^x with b in R
- any combination that you can get by
- adding (e.g. x^2 + x^3 + sin(x)),
- multiplying (e.g. sin(x)*x^2) or
- inserting (e.g. sin(x^2))
© Programmers or respective owner