3 ms·
AFAIK, return statements are literally the only place where brace style is affected by ASI. var result = { key: "value" }; return resu
by mc808 11y ago
AFAIK, return statements are literally the only place where brace style is affected by ASI.
var result =
{
key: "value"
};
return result;
works fine, plus it lets you more easily break on the return statement and verify/modify what will be returned when debugging. It would be kind of awkward to see braces like that in JavaScript, but a style guide could just ban returning object literals and make the ASI issue moot (at least regarding braces; you still have the other gotchas with forgetting a comma in a variable declaration, etc).
- Roboprog 11y agoGod I hate the term "semicolon insertion". It's a line oriented language, like shell or BASIC. You only need semicolons when you put multiple statements on a line (like a minifier does). Alas, like Ruby, JS does not require, or allow, an explicit line continuation, such as a backslash or ampersand. I hate the asshole at Netscape who decided the browser scripting language had to be modeled after Java (C/C++, in other words), especially when it was clearly meant to be a functional programming language that worked with lists and property lists. Man, I'm feeling "troll-ish" tonight. Not that I'm lying, just being blunt.