在這種情況下解決jslint錯誤的正確方法是什麼?我將一個getter函數添加到使用此函數的對象中。我不知道如何在循環內創建函數。通過使用loopfunc
option在文件的頂部不要在循環中創建函數
function dummy() {
return this.name_;
}
// Or: var dummy = function() {return this.name;};
for (var i = 0; i<processorList.length; ++i) {
result[i] = {
processor_: timestampsToDateTime(processorList[i]),
name_: processorList[i].processorName,
getLabel: dummy
};
}
...或者只是忽略該消息:
for (var i = 0; i<processorList.length; ++i) {
result[i] = {
processor_: timestampsToDateTime(processorList[i]),
name_: processorList[i].processorName,
getLabel: function() { // TODO solve function in loop.
return this.name_;
}
};
}
爲什麼不能沉默完全錯誤的jslint錯誤? [Here's](http://stackoverflow.com/a/40060701/307454)如何。 – lifebalance 2016-10-22 12:39:27
因爲錯誤是有原因的。我認爲編寫這樣的代碼非常好,其中許多完全相同的函數是在沒有真正原因的情況下創建的。 – 2016-10-26 08:02:52
_Sometimes_ JSLint的不一定是最終引導正確的編碼風格... – lifebalance 2016-10-26 18:31:04