3

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?

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Tim Lambert
  • 101
  • 1
  • 9
  • 3
    "Dynamic code evaluation" in Javascript is basically just "eval". Here's a good link on why "eval" *ISN'T* necessarily "Evil": http://www.nczonline.net/blog/2013/06/25/eval-isnt-evil-just-misunderstood/ IMHO... – paulsm4 Oct 27 '13 at 03:57
  • Related http://stackoverflow.com/questions/42934/what-do-people-find-so-appealing-about-dynamic-languages – megawac Oct 27 '13 at 03:57
  • possible duplicat of http://programmers.stackexchange.com/questions/157698/what-is-meant-by-dynamic-code-evaluation – Arun P Johny Oct 27 '13 at 03:57
  • Aron, that duplicate is not from stackoverflow.com and also, it is an unclear answer. – Tim Lambert Oct 27 '13 at 04:02
  • 1
    You can use [` – mu is too short Oct 27 '13 at 04:15

1 Answers1

3

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.

kol
  • 27,881
  • 12
  • 83
  • 120