Effective JavaScript Reviewed
github.com
github.com
One can just as easily say, "If you were using CoffeeScript this nonsense could have been avoided" :-)
Adding a semicolon to the start of your IIFE doesn't really hurt, but it's a workaround more than a solution.
These are conventions, not because you have to, but because you avoid other issues further down. You COULD simply write all your scripts inline.. and if you are judicious it is probably a bit better performing. That doesn't mean you want to... JavaScript in practice is much more about convention to prevent/limit obstacles than a "one right way" philosophy.
Hell, look at CommonJS vs AMD and the various solutions there alone... not even including all the one-off processes that have been used over the years.
I think I picked this example in a bootless attempt to humblebrag by pointing out something I'd been cargo culting.
I hope it's clear that I'm not suggesting there are no other ways to solve this problem. I just tried to pick an example of something I actually learned reading the book that arose as a consequence of things I thought I already knew but hadn't put together.
I was trying to give a sense of why, if you look at the TOC and see that it discusses topics A, B, and C that you already know, you may be very pleasantly surprised when you read the book by something you didn't know about A+B, B+C, A+C, or A+B+C.
Here is the 45% off discount code: IUGD45 (45%)
In most cases, however, the eBooks (Kindle) are cheaper on Amazon, but I am willing to pay a few dollars more to get the eBooks in all 3 formats (.pdf. .epub, and .pdf). I personally prefer to use iBooks (.epub works fine), when I am on my iPad, and the .pdf—when I am on my laptop.
As I pointed out, I was using this idiom out of superstition, I didn't fully understand what it did and why I was doing it. Now that I read The Fine Book, I'm in a better position to evaluate whether it is necessary and why other approaches may be superior.
I see that the review could be improved by explaining that the idiom is not something the book recommends pr se, but rather something I understood once I read the book.
Of course that begs the question if this is necessary at all since I personally haven't seen it used but I haven't read the source of many JavaScript projects either.
Besides, you don't necessarily want all files to be automatedly wrapped in a function. jQuery for example would break.