【发布时间】:2016-09-28 22:03:36
【问题描述】:
我在 react JS 中有一个小代码 sn-p,其中我试图在对象“类别”中搜索一个值,然后将相应的键值对插入到新映射 sortedCategories 中。
var categoriesToSort = []; //categoriesToSort has some values
var sortedCategories = new Map();
for(var j = 0 ; j < categoriesToSort.length ; j++) {
categories.forEachMap(function(key, value){
if(categoriesToSort[j] === value) {
sortedCategories.set(key, value);
}
});
}
但这给了我以下 lint 错误,我没有得到任何解决方法。
不要在循环中创建函数
【问题讨论】:
-
这已被问到once or twice before。很好的答案here,等等。投票结束。
标签: javascript node.js reactjs jslint