What is Dynamic Code Evaluation as mentioned by John Resig

佐手、 提交于 2019-12-12 15:49:38

问题


In his book "Secrets of the Javascript Ninja", John Resig writes:

Although dynamic code evaluation has been maligned due to its complexity and potential for security issues, without it we wouldn’t have had the CoffeeScript programming language.

I was hoping that someone could explain what is Dynamic Code Evaluation? Also, are there any code examples (or word examples) that would help better explain it? Furthermore, are there any website examples that use dynamic code evaluation?

Also, if possible, how did dynamic code evaluation bring about the CoffeeScript programming language?


回答1:


Dynamic code evaluation techniques in JavaScript:

  • eval function
  • Function object, created with the Function constructor

Basically you take a string (for example, concatenate it from parts) which contains JavaScript code, and use one of these techniques to parse and run it. The CoffeeScript compiler is actually a transpiler: it takes source code written in CoffeeScript (that is, a string), and translates it into JavaScript source code (another string), which is run using eval.



来源:https://stackoverflow.com/questions/19614457/what-is-dynamic-code-evaluation-as-mentioned-by-john-resig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!