Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think more that the bug is in the code that's doing the wrapping, and therefore the fix should also be in the code doing the wrapping, and not in the code being wrapped.


The problem is if you're using 3rd party libs, especially if the 3rd party code is coming from developers with the philosophy that ASI is a good thing and intentionally leave out the semi-colons from their code. Adding the semi-colon to the code you control is safe and doesn't hurt anything.


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.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: