来自Google JavaScript 样式指南:
// 1.
MyClass.prototype.myMethod = function() {
return 42;
} // No semicolon here.
(function() {
// Some initialization code wrapped in a function to create a scope for locals.
})();
var x = {
'i': 1,
'j': 2
} // No semicolon here.
// 2. Trying to do one thing on Internet Explorer and another on Firefox.
// I know you'd never write code like this, but throw me a bone.
[normalVersion, ffVersion][isIE]();
var THINGS_TO_EAT = [apples, oysters, sprayOnCheese] // No semicolon here.
// 3. conditional execution a la bash
-1 == resultOfOperation() || die();
1 - JavaScript 错误 - 首先以第二个函数作为参数调用返回 42 的函数,然后“调用”数字 42 导致错误。
2 - 当它试图调用 x[ffVersion]isIE 时,您很可能会在运行时收到“未定义中没有此类属性”错误。
3 - die 被调用,除非 resultOfOperation() 是 NaN 并且 THINGS_TO_EAT 被分配 die() 的结果。