Do You Name Your Anonymous Function In A Function Expression?
I'm using firebug here, and trying to write a blog post to demonstrate something just like these code. // Unnamed Anonymous Function var count1 = function () { var x = 0, f; f
Solution 1:
Named function expressions can be great for debugging, just be aware that they can cause problems with older versions of internet explorer, so be careful.
This article goes into all the details, but the short version is that NFEs in IE can wind up getting hoisted as though they were function declarations, causing you to have to clean up in ways you shouldn't have to:
var f = (function(){
var f, g;
if (true) {
f = functiong(){};
}
else {
f = functiong(){};
}
// null `g`, so that it doesn't reference extraneous function any longer
g = null;
return f;
})();
Post a Comment for "Do You Name Your Anonymous Function In A Function Expression?"