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: