我是 js 新手,有时我很难习惯它的代码约定。所以我有一个问题,我应该如何声明函数表达式?看看我的代码,我是怎么做的,还是有更好的做法?
function onAddButtonClick() {
var engWord = document.getElementById('engWord'),
japWord = document.getElementById('japWord'),
engVal = engWord.value,
japVal = japWord.value,
engExpr = (engVal !== ""),
japExpr = (japVal !== ""),
duplicateNum,
checkImg,
numOfWords;
duplicateNum = (function () {
var i,
pair;
for (i = 0; i < dictionary.length; i++) {
pair = dictionary[i];
if (pair.eng === engVal && pair.jap === japVal) {
return 3;
} else if (pair.jap === japVal) {
return 2;
} else if (pair.eng === engVal) {
return 1;
}
}
return 0;
}());
//remove focus from inputs
engWord.blur();
japWord.blur();
...
}
提前致谢。