I am working with jQuery and I need to create an anonymous method with the eval () function.
The following lines worked with Opera, but not with IE, FF, Chrome:
var callbackStr = "function(){alert('asdf');}";
var callback = eval(callbackStr);
callback();
This code works with all browsers:
var callbackStr = "var callback = function(){alert('asdf');}";
eval(callbackStr);
callback();
You see, I have already solved my problem. But I want to know what exactly is happening. Can someone explain this behavior to me or let me know where I can find additional information?
(PS: I know this page .)
source
share