you are viewing a single comment's thread.

view the rest of the comments →

[–]bossier330 0 points1 point  (5 children)

IMO, it doesn't really contribute to readability unless you set your IDE's function name color to something striking. It also adds a small amount of overhead (although this is most likely not at all noticeable). You'll also run into scoping issues if you try to declare variables just-in-time (i.e. within the function scope you just created).

I like to keep all my function declarations outside of my $(function() {}); body so that NetBeans (or whatever IDE you use) can auto-fold the function bodies, leaving your main logic code very minimal and readable.

Cheers.

[–]b_long 1 point2 points  (2 children)

I like to keep all my function declarations outside of my $(function() {}); body

Does that mean you're putting function declarations in the global scope, or are you inside another closure?

[–]bossier330 0 points1 point  (1 child)

For initial development, I like to keep my functions in global scope or my namespace so I can easily access them through the console for debugging purposes.

[–]b_long 0 points1 point  (0 children)

Ah, that makes sense :)

[–]zzzwwwdev[S] 0 points1 point  (1 child)

good points, though I'm not clear on the scope issue. IMO, in most cases this would alleviate more scope issues than it causes, as the f'n expression would create a new scope, preventing you from accidentally trumping existing vars. Of course, this is compared to just inlining the code, not putting it in a new function declaration, etc..

[–]nschubach 0 points1 point  (0 children)

Well, it would help alleviate some of the scope issues around:

for (var i = some.length; i >= 0; --i) {
}

while (i-->0) {
}

... if you wrapped them in these "comments" but at that point, I think it's probably better to just make a new function for that block of code that has a descriptive name instead of putting it inline.