我使用的是Apatana 3,我修改了JS代码格式化程序,让它看起来更清晰,下面是格式化后的代码,它给我一个错误:
copyOffset : function( index ) { return { x : index, y : index }; }萤火虫给我:
SyntaxError: invalid label如果我将其更改为:
copyOffset : function( index ) { return{ x : index, y : index }; }没问题,任何人都可以告诉我这两个回报声明有什么区别?
I'm using Apatana 3, i modified the JS code formatter a little bit to let it seem more clear, below is the code after format, it give me an error:
copyOffset : function( index ) { return { x : index, y : index }; }firebug give me:
SyntaxError: invalid labelif i change it to:
copyOffset : function( index ) { return{ x : index, y : index }; }will be OK, Anybody who can tell me what's the diff between these two return statement?
最满意答案
不同的是,第一个片段实际上被解释为...
copyOffset : function( index ) { return; { x : index, y : index }; }它被称为自动分号插入 :当JavaScript解析器看到似乎完整的语句,但错过了分号时,它会尝试“修复”它。
是的,尽管有时很有帮助,但它可能很烦人。 本文详细介绍了此JavaScript功能。
The difference is that the first snippet is actually interpreted as...
copyOffset : function( index ) { return; { x : index, y : index }; }It's called Automatic Semicolon Insertion: when JavaScript parser sees a statement that seems to be complete, but misses semicolon, it attempts to 'fix' it.
And yes, even though helpful at times, it can be quite annoying. This article explains this JavaScript feature in details.
更多推荐
发布评论