Is there ever a good reason to use eval()?

后端 未结 10 1076
清歌不尽
清歌不尽 2020-12-03 20:51

It seems to me that eval() is treated with the same disdain that goto is. And by eval, I mean a function for executing a string as code, as seen in

10条回答
  •  抹茶落季
    2020-12-03 21:19

    When creating/testing code segments eval is PERFECT!

    Just build a basic scaffolding webpage with textareas and an eval button. Put code into a textarea then press eval button. It's faster than switching back and forth between your text editor and browser

    eval

    edit code
    press eval button
    

    switching method

    edit code
    press save          extra step
    switch to browser   extra step
    press reload
    

    When doing alot of testing and tweaking on the code the minor extra steps can really add up. Plus you might forget to save creating confusion when testing.

提交回复
热议问题