Why does eval() exist?

后端 未结 6 814
执笔经年
执笔经年 2020-12-09 01:49

Many programmers say it is a bad practice to use the eval() function:

When is JavaScript's eval() not evil?

6条回答
  •  情深已故
    2020-12-09 02:31

    eval() exists because sometimes you want to give complete programmatic control of your application to code passed in at run time.

    Languages without an eval() feature can definitely provide (a subset? all?) of this functionality by asking each programmer to essentially write their own eval() -- lex the input, parse the input, create new objects as necessary, run methods or functions on them via simple string comparisons or similar. In essence, duplicate the entire interpreter that already exists and is debugged and fast.

提交回复
热议问题