John Resig提到的动态代码评估是什么 [英] What is Dynamic Code Evaluation as mentioned by John Resig

查看:115
本文介绍了John Resig提到的动态代码评估是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

John Resig在他的《 Java忍者的秘密》一书中写道:

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

尽管动态代码评估由于其复杂性和潜在的安全隐患而受到损害,但如果没有它,我们就不会拥有CoffeeScript编程语言.

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?

如果可能的话,动态代码评估如何带来CoffeeScript编程语言?

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

推荐答案

JavaScript中的动态代码评估技术:

Dynamic code evaluation techniques in JavaScript:

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

基本上,您需要一个包含JavaScript代码的字符串(例如,从各个部分连接起来),并使用以下一种技术来解析和运行它. CoffeeScript编译器实际上是翻译器:它需要用CoffeeScript编写的源代码(是一个字符串),并将其转换为使用eval运行的JavaScript源代码(另一个字符串).

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.

这篇关于John Resig提到的动态代码评估是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆