JSLint “eval is evil.” alternatives

后端 未结 7 1350
别那么骄傲
别那么骄傲 2021-02-13 22:49

I am have some JavaScript functions that run on both the client (browser) and the server (within a Java Rhino context). These are small functions - basically little validators

7条回答
  •  执笔经年
    2021-02-13 23:33

    You can use

    setInterval("code to be evaluated", 0);
    

    Internally, if you pass setInterval a string it performs a function similar to eval().

    However, I wouldn't worry about it. If you KNOW eval() is evil, and take appropriate precautions, it's not really a problem. Eval is similar to GoTo; you just have to be careful and aware of what you're doing to use them properly.

提交回复
热议问题