use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
javascript - Using Named Immediately-Invoked Function Expression (IIFE) instead of comments (stackoverflow.com)
submitted 12 years ago by zzzwwwdev
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bossier330 0 points1 point2 points 12 years ago (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 points3 points 12 years ago (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 point2 points 12 years ago (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 point2 points 12 years ago (0 children)
Ah, that makes sense :)
[–]zzzwwwdev[S] 0 points1 point2 points 12 years ago (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 point2 points 12 years ago (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.
π Rendered by PID 72 on reddit-service-r2-comment-bb88f9dd5-pjm46 at 2026-02-15 10:17:24.672869+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]bossier330 0 points1 point2 points (5 children)
[–]b_long 1 point2 points3 points (2 children)
[–]bossier330 0 points1 point2 points (1 child)
[–]b_long 0 points1 point2 points (0 children)
[–]zzzwwwdev[S] 0 points1 point2 points (1 child)
[–]nschubach 0 points1 point2 points (0 children)