Re:Javascript patterns
by russellsprouts on Thursday January 02, 2014 @01:30AM
(#6998494)
Rather than putting a semi-colon after every function declaration, I would suggest the Lua convention -- put the semi-colon at the beginning of the line that could cause issues. An empty statement is valid is JavaScript, so this should work in all cases I can think of:
In Lua, whitespace is very nearly all the same. For example:
is valid Lua code. However, lines that start with parens have the same ambiguity:
The parser will complain about the ambiguity. If the intention is to have 1 statement, they should probably be on the same line, otherwise the convention is to put the semi-colon at the beginning of the second line:
[ Parent
| on HN ]
That would be a change of paradigm because no JavaScript standard -or library- does that. Plus it feels wrong because the spoken language equivalent would be something like:
The quick brown fox jumps over the lazy dog
. The fox didn't say anything that day
, because in all honesty what does the fox say
?