consider adding more "[no LineTerminator here]" to avoid problem caused by omit the semicolon
程劭非
csf178 at gmail.com
Fri Jun 22 02:08:57 PDT 2012
Hi, everyone,
During some recent discussion in Chinese JS community, I've noticed
several case which JS behave out of user's expect if omitting the
semicolon.
See the following code:
--------------------------------------------
var a = this.a //!!!! here no semicolon will be auto inserted
[1,2,3].forEach(function(){
// do something
})
--------------------------------------------
(function(){
//do something
})() //!!!! here no semicolon will be auto inserted
(function(){
//do something else
})()
--------------------------------------------
I was thinking that if we could change some grammar rules to make it
behave as most user's expect. Just adding several [no LineTerminator
here] will do so:
--------------------------------------------
CallExpression :
MemberExpression [no LineTerminator here] Arguments
CallExpression [no LineTerminator here] Arguments
CallExpression [no LineTerminator here] [ Expression ]
CallExpression . IdentifierName
--------------------------------------------
Though some of you might consider omitting the semicolon as a bad
style, but its used by several group and company (including zepto.js
and npmjs). I think this change will benefit them a lot with very
small side effect.
/Shaofei
More information about the es-discuss
mailing list