V
V
Vasily Serpokryl2015-12-28 23:01:12
JavaScript
Vasily Serpokryl, 2015-12-28 23:01:12

How to recognize a function from a string in JS?

For example, there is a line "sin(30)-0.5+12*x-16" How can this line be turned into a function of the form:
function (x) { return Math.sin(30)-0.5+12*x-16;}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artcl, 2015-12-28
@graf_777_gos

new Function('x', 'return Math.sin(30) - 0.5 + 12 * x - 16;');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question