Eval is evil… So what should I use instead?

前端 未结 9 1001
忘掉有多难
忘掉有多难 2020-11-27 17:27

An ajax request returns me a standard JSON array filled with my user\'s inputs. The input has been sanitized, and using the eval() function, I can easily create my javascrip

相关标签:
9条回答
  • 2020-11-27 18:22

    If you're certain there's no injection risk, and you're not eval()ing in a loop, then use eval(). It will compare favorably to other options which will certainly be slower, might break, and will require the client to download additional code.

    0 讨论(0)
  • 2020-11-27 18:25

    Compare to the command design pattern: http://en.wikipedia.org/wiki/Command_pattern. Given this, you can precisely define the operations a client can execute and your application will be as safe as the underlying interpretation.

    0 讨论(0)
  • 2020-11-27 18:25

    Depends on what you're trying to accomplish with the sanitation. I've had great success w/the prototype framework's support for JSON and safe evaluation.

    0 讨论(0)
提交回复
热议问题