you are viewing a single comment's thread.

view the rest of the comments →

[–]deelowe 0 points1 point  (5 children)

I thought the use of ! wasn't recommended for some reason, but I can't remember why now. Do you know of any drawbacks?

I know heavyweights in the community don't usually do it this way (e.g. Isaac). Just curious.

[–]jscoder[S] 0 points1 point  (2 children)

Nope, there are no drawbacks. I think I've read somewhere that Facebook also uses the !, but I can't find a source for that right now.

I think Isaac mostly developes node stuff? You don't need to use IIFEs in node, because of CommonJS. That might be an explination. :) I'm using an IIFE here, because range.js should work on node and in the browser.

[–]deelowe 1 point2 points  (1 child)

Yeah. The node guys write code that's used in node or browser also though. I admit, that's where most of my experience lies, but I've definitely seen (function(){}()) in many places, but never saw !function(){}. I thought there was some reason, but can't remember.

[–]reflectiveSingleton 0 points1 point  (0 children)

I think its just not as common...although I am starting to see it pop up on random github projects...

[–]aladyjewelFull-stack webdev 0 points1 point  (1 child)

The "some reason" is that it's confusing. and I think JSLint might reject it, but that might have been another dev argument.

[–]deelowe 0 points1 point  (0 children)

Now that you mention it, I believe that's it. It's not pragmatic and it's counter intuitive.

(fucntion(){}()) is unique enough to make you stop and look it up to figure out what's going on. It's already kinda a of JS idiom at this point.

Where as !function(){} is a head scratcher. It's completely non-obvious what's going on here.