Live data from Hacker News

Writing great Javascript

oli.me.uk

11–12 of 12 posts

Re: Writing great Javascript

#11
post #7

Earlier quoted context omitted.

But what if you do this: You need the semicolon at both ends to insulate your script from the unknown coding style or 3rd party scripts which may be appended or prepended to yours. If 3rd party A omits a trailing semicolon, or 3rd party B doesn't uses your semicolon prefix style then by wrapping your script in semicolons you pre-emptively prevent problems. I believe this is an example of the wider coding style called…

Or you could actually just read the source code of the libs you are using...

It's pretty easy to miss a terminating semicolon which will waste time, but the real use case is for people who are writing the libs that other people are using; they have absolutely no knowledge or control of what other javascript might be prependend or appended onto theirs.

Re: Writing great Javascript

#12
post #7

Earlier quoted context omitted.

But what if you do this: You need the semicolon at both ends to insulate your script from the unknown coding style or 3rd party scripts which may be appended or prepended to yours. If 3rd party A omits a trailing semicolon, or 3rd party B doesn't uses your semicolon prefix style then by wrapping your script in semicolons you pre-emptively prevent problems. I believe this is an example of the wider coding style called…

Or you could actually just read the source code of the libs you are using...

Yeah. So I add a trailing semicolon. Then the 3rd party library releases an update. I have to remember to merge my patch every time they update, do I?
Post reply on HN