在这种情况下解决 jslint 错误的正确方法是什么?我正在向使用它的对象添加一个 getter 函数。我不知道如何在不创建循环内的函数的情况下执行此操作。
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_;
}
};
}
将函数移到循环之外:
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
};
}
...或者只是使用忽略该消息loopfunc option http://www.jshint.com/docs/options/#loopfunc在文件顶部:
/*jshint loopfunc:true */
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)