“Mutable variable is accessible from closure” in a function passed to Array.prototype.every

ぃ、小莉子 提交于 2019-12-01 18:58:12

Having gotten confirmation from the comments above that this warning is basically a false positive, I modified the code to ignore the warning message:

topArray.every(function(element, index) {
    //noinspection JSReferencingMutableVariableFromClosure
    if (element.innerArray && element.innerArray.length < minValue) {
        minValue = element.innerArray.length;
        candidateIndex = index;
        //noinspection JSReferencingMutableVariableFromClosure
        if (minValue == 0) {
            return false;
        }
    }
    return true;
});

(The warning only triggers when comparing the value, as opposed to when setting it.)

I'm eager to hear any other answers, but if I don't, I'll accept this answer in about a week.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!