If you prefix ( and [ with semicolons you're good to go. Nowhere else are they needed, and the problems with ASI aren't solved by using semicolons everywhere.
e.g.
function foo() {
return
{
something: 'here'
}
}
Using semis everywhere doesn't save you from ASI, you just have to be careful about line breaks. Whether you use semis or not. The problem isn't omitting semicolons, it's inserting spurious newlines. Keep braces on the same line as returns or wrap the returned expression in parens, return (....
You have to know the rules either way. It doesn't matter whether or not you use them, it's purely a style thing. Either way we shouldn't try to make anyone else conform to our preferred style unless they're contribution to a project.
edit: Downvotes but no rebuttals. If you ask me that's pretty telling.
That's a straw man, nobody writes code like that. You should be writing it one of these ways:
var f = function(){},
x = 9
or
var f = function(){}
var x = 9
If you want to write it on one line you obviously need a semi colon. But if anyone wrote code like that in a project I worked on I would fix it, that's just stupid unless it's something trivial like var a = 1, b = 2 which would still be only one statement.
I may have misunderstood. I was thinking you were implying this code would work minified, when it wouldn't. But I see somewhere else you said that the minifier should be a proper javascript parser (the more popular ones aren't, hence the argument).
So n/m. But semicolon insertion is a mis-feature anyway. White space should either be significant or not, not sometimes significant.
-2
u/sjs Feb 06 '11 edited Feb 06 '11
If you prefix ( and [ with semicolons you're good to go. Nowhere else are they needed, and the problems with ASI aren't solved by using semicolons everywhere.
e.g.
Using semis everywhere doesn't save you from ASI, you just have to be careful about line breaks. Whether you use semis or not. The problem isn't omitting semicolons, it's inserting spurious newlines. Keep braces on the same line as returns or wrap the returned expression in parens,
return (....http://inimino.org/~inimino/blog/javascript_semicolons
http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
You have to know the rules either way. It doesn't matter whether or not you use them, it's purely a style thing. Either way we shouldn't try to make anyone else conform to our preferred style unless they're contribution to a project.
edit: Downvotes but no rebuttals. If you ask me that's pretty telling.