Jan 282012
 

Many JavaScript programmers treat eval & new Function construct as the same. But new Function & eval are NOT the same. the important difference is:-

  • eval() works within the current execution scope and can affect local variables.
  • new Function() cannot affect local variables because the code runs in a separate scope

So both are evil & should only be used when there is no other way but as you may notice new Function is slightly less evil

Related posts:

  1. JavaScript: I hate you but I Love you, too
  2. [JavaScript Bookmarklet] Convert All text on page into Lower Case

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>