- 函数
函数
无论是函数声明还是函数表达式,'('前不要空格,但'{'前一定要有空格;
函数调用括号前不需要空格;
立即执行函数外必须包一层括号;
不要给inline function命名;
参数之间用', '分隔,注意逗号后有一个空格。
// no space before '(', but one space before'{'var doSomething = function(item) {// do something};function doSomething(item) {// do something}// not gooddoSomething (item);// gooddoSomething(item);// requires parentheses around immediately invoked function expressions(function() {return 1;})();// not good[1, 2].forEach(function x() {...});// good[1, 2].forEach(function() {...});// not goodvar a = [1, 2, function a() {...}];// goodvar a = [1, 2, function() {...}];// use ', ' between function parametersvar doSomething = function(a, b, c) {// do something};
