0

Can anyone suggest a reason why this may be better or worse than using eval() for AJAX calls? I think I found on a Google related page that advocated it over eval() since eval runs in the global scope whereas the functions contents here don't.

str = '{a: 90, b: 99}';
callback = new Function ('return ' + str);
obj = callback();
Richard
  • 4,809
  • 3
  • 27
  • 46

1 Answers1

3

It is effectively eval with messier syntax. It has all the drawbacks of eval.

The function body will still have access to the global scope. It is still slow. Bad data will throw exceptions. Untrusted data can utilise XSS.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335