Taking the jQuery framework, for example, if you run code like this:
$(document).ready(function init() { foo.bar(); });
The stack trace in Firebug will look like this:
init() anonymous() anonymous([function(), init(), function(), 4 more...], function(), Object name=args) anonymous() anonymous()
As you can see, this is not very readable because you need to click on each function to find out what it is. Anonymous functions are also displayed as (?)() In the profiler, and they can lead to the error " cannot access optimized close ". It seems to me that these are good reasons to avoid them. Then there is the fact that ECMAScript 5 will condemn arguments.callee in its strict mode, which means that it will not be possible to refer to anonymous functions with it, which makes them a little less reliable for the future.
On the other hand, the use of these functions can lead to repetition, for example:
var Foo = { bar: function bar() {} } function Foo() {} Foo.prototype.bar = function bar() {}
Do I correctly believe that this repetition is justified in the light of the convenience of debugging called function functions, and that the prevalence of anonymous functions in a good framework such as jQuery is an oversight?
javascript function jquery debugging expression
slikts
source share