在这种情况下解决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