Hacker News new | past | comments | ask | show | jobs | submit login

If you're using a library that stitches together multiple JavaScript files - all of which work when included via separate script tags - and the resultant file doesn't work (due to the issue mentioned in TFA at least), then that's a bug in the library that stitches multiple JavaScript files together, and should be fixed there.

Adding a semicolon to the start of your IIFE doesn't really hurt, but it's a workaround more than a solution.




I came across this issue when stitching some files together for min/merge... I simply had the merge process insert a semicolon after each file, for effectively the same reason.. multiple semicolons aren't going to hurt anything... The reason for wrapping your script in an anonymous function is similar, not polluting the global namespace, or at least not relying on certain globals.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: