Function declared in a loop contains unsafe references to variable(s) 'window', 'window'.
3729 const dataRow = $(this).attr('data-nu-row')
3730 $("[data-nu-row='" + dataRow + "']").not('.nuCellColored').addClass('nuSelectBrowse').removeClass('nuBrowseTable')
3731 }
3732 }, function () {3733 if (window.nuBROWSERESIZE.moving_element == '') {3734 $('[data-nu-row]').addClass('nuBrowseTable').removeClass('nuSelectBrowse')37353736 window.nuBROWSEROW = -137373738 const dataRow = $(this).attr('data-nu-row')3739 $("[data-nu-row='" + dataRow + "']").addClass('nuBrowseTable').removeClass('nuSelectBrowse')3740 }3741 })3742 }
3743
3744 if (r == 0 && c == 0) {
Function declared in a loop contains unsafe references to variable(s) 'window', 'window'.
3716 .attr('onclick', 'nuSelectBrowse(event, this)')
3717 .hover(
3718
3719 function () {3720 if (window.nuBROWSERESIZE.moving_element == '') {3721 if (this.offsetWidth < this.scrollWidth && !$(this).is('[title]')) {3722 $(this).attr('title', $(this).html().replace(/(<([^>]+)>)/ig, '')) // Remove HTML tags3723 }37243725 $('[data-nu-row]').addClass('nuBrowseTable').removeClass('nuSelectBrowse')37263727 window.nuBROWSEROW = -137283729 const dataRow = $(this).attr('data-nu-row')3730 $("[data-nu-row='" + dataRow + "']").not('.nuCellColored').addClass('nuSelectBrowse').removeClass('nuBrowseTable')3731 }3732 }, function () {3733 if (window.nuBROWSERESIZE.moving_element == '') {
3734 $('[data-nu-row]').addClass('nuBrowseTable').removeClass('nuSelectBrowse')
3735
Function declared in a loop contains unsafe references to variable(s) 'i'.
4339 for (var i = 0; i < c.length; i++) {
4340 if (c[i].subform) {
4341 $('#' + c[i].id + 'scrollDiv' + ' > .nuSubform1').remove()
4342 $('#' + c[i].id + 'scrollDiv' + ' > .nuSubform0').each(function () {4343 if ($(this)[0].id != c[i].id + '000nuRECORD') {4344 $(this).remove()4345 }4346 })4347
4348 const k = $('#' + c[i].id + '000nuRECORD').children()
4349
Function declared in a loop contains unsafe references to variable(s) 'i', 'i', 'nuSetSearchColumn'.
4621 .attr('onclick', 'nuClickSearchColumn(event);')
4622 .addClass('nuOptionsItem')
4623 .html(nobr)
4624 .click(function () {4625 const cb = $('#nuSearchList' + i).attr('checked')46264627 $('#' + 'nuSearchList' + i).attr('checked', !cb)46284629 nuSetSearchColumn()4630 })4631
4632 if (i < 9) {
4633 const shortcut_key = document.createElement('div')
Function declared in a loop contains unsafe references to variable(s) 'nuBuildLookup'.
1021
1022 if (c == 2) { // -- button
1023 $('#' + o[c])
1024 .on('click', function () {1025 nuBuildLookup(this, '')1026 })1027 }
1028 }
1029 })
Function declared in a loop contains unsafe references to variable(s) 'match'.
1242 match = this.makeBruteforceMatch(i, passwordCharIndex)
1243 const tmp = this.optimal.m[i - 1] // eslint-disable-next-line no-loop-func
1244
1245 Object.keys(tmp).forEach(sequenceLength => {1246 const lastMatch = tmp[sequenceLength] // corner: an optimal sequence will never have two adjacent bruteforce matches.1247 // it is strictly better to have a single bruteforce match spanning the same region:1248 // same contribution to the guess product with a lower length.1249 // --> safe to skip those cases.12501251 if (lastMatch.pattern !== 'bruteforce') {1252 // try adding m to this length-sequenceLength sequence.1253 this.update(match, parseInt(sequenceLength, 10) + 1)1254 }1255 })1256 }
1257 },
1258
Function declared in a loop contains unsafe references to variable(s) 'dir', 'dir', 'dir', 'colMax', 'dir', 'colMax', 'dir', 'dir', 'dir', 'dir', 'dir'.
1724 colMax = c.cache[tbodyIndex].colMax
1725 rows = c.cache[tbodyIndex].normalized
1726
1727 rows.sort(function (a, b) {1728 let sortIndex, num, col, order, sort, x, y1729 // rows is undefined here in IE, so don't use it!1730 for (sortIndex = 0; sortIndex < sortLen; sortIndex++) {1731 col = sortList[sortIndex][0]1732 order = sortList[sortIndex][1]1733 // sort direction, true = asc, false = desc1734 dir = order === 017351736 if (c.sortStable && a[col] === b[col] && sortLen === 1) {1737 return a[c.columns].order - b[c.columns].order1738 }17391740 // fallback to natural sort since it is more robust1741 num = /n/i.test(ts.getSortType(c.parsers, col))1742 if (num && c.strings[col]) {1743 // sort strings in numerical columns1744 if (typeof (ts.string[c.strings[col]]) === 'boolean') {1745 num = (dir ? 1 : -1) * (ts.string[c.strings[col]] ? -1 : 1)1746 } else {1747 num = (c.strings[col]) ? ts.string[c.strings[col]] || 0 : 01748 }1749 // fall back to built-in numeric sort1750 // var sort = $.tablesorter['sort' + s]( a[col], b[col], dir, colMax[col], table );1751 sort = c.numberSorter1752 ? c.numberSorter(a[col], b[col], dir, colMax[col], table)1753 : ts['sortNumeric' + (dir ? 'Asc' : 'Desc')](a[col], b[col], num, colMax[col], col, c)1754 } else {1755 // set a & b depending on sort direction1756 x = dir ? a : b1757 y = dir ? b : a1758 // text sort function1759 if (typeof textSorter === 'function') {1760 // custom OVERALL text sorter1761 sort = textSorter(x[col], y[col], dir, col, table)1762 } else if (typeof sorter[col] === 'function') {1763 // custom text sorter for a SPECIFIC COLUMN1764 sort = sorter[col](x[col], y[col], dir, col, table)1765 } else {1766 // fall back to natural sort1767 sort = ts['sortNatural' + (dir ? 'Asc' : 'Desc')](a[col] || '', b[col] || '', col, c)1768 }1769 }1770 if (sort) { return sort }1771 }1772 return a[c.columns].order - b[c.columns].order1773 })1774 }
1775 if (ts.debug(c, 'core')) {
1776 console.log('Applying sort ' + sortList.toString() + ts.benchmark(sortTime))
Function declared in a loop contains unsafe references to variable(s) 'litem'.
462 marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + '%'),
463 marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + '%') : '0',
464 borderCollapse: 'collapse'
465 }).find('td').click(function (e) { 466 const $t = $(this) 467 const h = $t.html() 468 let n = parseInt(h.replace(/[^0-9]/g), 10) 469 const ap = h.replace(/[^apm]/ig) 470 const f = $t.data('for') // loses scope, so we use data-for 471 472 if (f === 'hour') { 473 if (ap.indexOf('p') !== -1 && n < 12) { 474 n += 12 475 } else { 476 if (ap.indexOf('a') !== -1 && n === 12) { 477 n = 0 478 } 479 } 480 } 481 482 tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n) 483 484 tp_inst._onTimeChange() 485 tp_inst._onSelectHandler() 486 }).css({ 487 cursor: 'pointer',
488 width: (100 / gridSize[litem]) + '%',
489 textAlign: 'center',
Function declared in a loop contains unsafe references to variable(s) 'temptop', 'templeft', 'tempright', 'templeft', 'transx', 'tempbottom', 'temptop', 'transy', 'templeft', 'transx', 'w', 'w', 'transx', 'templeft', 'transx', 'templeft', 'temptop', 'transy', 'h', 'h', 'transy', 'temptop', 'transy', 'temptop', 'tempright', 'w', 'w', 'tempright', 'tempbottom', 'h', 'h', 'tempbottom'.
8842 let temptop, templeft, tempbottom, tempright
8843
8844 for (let i = 0; i < clses.length; i++) {
8845 $(this).find('.' + clses[i]).each(function () { 8846 temptop = $(this).offset().top - plottop 8847 templeft = $(this).offset().left - plotleft 8848 tempright = templeft + $(this).outerWidth(true) + transx 8849 tempbottom = temptop + $(this).outerHeight(true) + transy 8850 if (templeft < -transx) { 8851 w = w - transx - templeft 8852 transx = -templeft 8853 } 8854 if (temptop < -transy) { 8855 h = h - transy - temptop 8856 transy = -temptop 8857 } 8858 if (tempright > w) { 8859 w = tempright 8860 } 8861 if (tempbottom > h) { 8862 h = tempbottom 8863 } 8864 }) 8865 }
8866
8867 newCanvas.width = w + Number(x_offset)
Function declared in a loop contains unsafe references to variable(s) 'i'.
59 for (var i = 0, e = lines.length; i < e; ++i) {
60 if (i) callback('\n')
61 const stream = new CodeMirror.StringStream(lines[i], null, {
62 lookAhead: function (n) { return lines[i + n] },63 baseToken: function () {}
64 })
65 if (!stream.string && mode.blankLine) mode.blankLine(state)
Function declared in a loop contains unsafe references to variable(s) 'message', 'message'.
200
201 // filter out duplicate messages
202 var message = []
203 anns = anns.filter(function (item) { return message.indexOf(item.message) > -1 ? false : message.push(item.message) })204
205 let maxSeverity = null
206 const tipLabel = state.hasGutter && document.createDocumentFragment()
Function declared in a loop contains unsafe references to variable(s) 'previousWord', 'table', 'previousWord', 'previousWord'.
221
222 for (var i = 0; i < query.length; i++) {
223 const lineText = query[i]
224 eachWord(lineText, function (word) {225 const wordUpperCase = word.toUpperCase()226 if (wordUpperCase === aliasUpperCase && getTable(previousWord)) { table = previousWord }227 if (wordUpperCase !== CONS.ALIAS_KEYWORD) { previousWord = word }228 })229 if (table) break
230 }
231 }
Function declared in a loop contains unsafe references to variable(s) 'files', 'files', 'j', 'j', 'j', 'file', 'j', 'file', 'file', 'file', 'word'.
626 break
627 }
628 // found search word in contents
629 $u.each(_o, function (o) {630 let _files = o.files631 if (_files === undefined) { return }632633 if (_files.length === undefined) { _files = [_files] }634 files = files.concat(_files)635636 // set score for the word in each file to Scorer.term637 for (j = 0; j < _files.length; j++) {638 file = _files[j]639 if (!(file in scoreMap)) { scoreMap[file] = {} }640 scoreMap[file][word] = o.score641 }642 })643
644 // create the mapping
645 for (j = 0; j < files.length; j++) {
Function declared in a loop contains unsafe references to variable(s) 'file'.
670 if (valid) {
671 // select one (max) score for the file.
672 // for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
673 const score = $u.max($u.map(fileMap[file], function (w) { return scoreMap[file][w] }))674 results.push([filenames[file], titles[file], '', null, score])
675 }
676 }
Function declared in a loop contains unsafe references to variable(s) 'hidden', 'prop', 'prop', 'prop'.
6727
6728 /* eslint-disable no-loop-func */
6729
6730 anim.done(function () {6731 /* eslint-enable no-loop-func */67326733 // The final step of a "hide" animation is actually hiding the element6734 if (!hidden) {6735 showHide([elem])6736 }6737 dataPriv.remove(elem, 'fxshow')6738 for (prop in orig) {6739 jQuery.style(elem, prop, orig[prop])6740 }6741 })6742 }
6743
6744 // Per-property setup
Description
Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:
for (var i = 0; i < 10; i++)
funcs[i] = function() {
return i;
};
}
In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i in the scope.
let
or const
mitigate this problem.
for (let i = 0; i < 10; i++) {
funcs[i] = function() {
return i;
};
}
In this case, each function created within the loop returns a different number as expected.
Bad Practice
for (let i = 10; i; i--) {
(function() { return i; })();
}
while(i) {
const a = function() { return i; };
a();
}
do {
function a() { return i; };
a();
} while (i);
let foo = 0;
for (let i = 0; i < 10; ++i) {
//Bad, `foo` is not in the loop-block's scope and `foo` is modified in/after the loop
setTimeout(() => console.log(foo));
foo += 1;
}
for (let i = 0; i < 10; ++i) {
//Bad, `foo` is not in the loop-block's scope and `foo` is modified in/after the loop
setTimeout(() => console.log(foo));
}
foo = 100;
Recommended
let a = function() {};
for (let i = 10; i; i--) {
a();
}
for (let i = 10; i; i--) {
const a = function() {}; // OK, no references to variables in the outer scopes.
a();
}
for (let i = 10; i; i--) {
const a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
a();
}
const foo = 100;
for (let i = 10; i; i--) {
const a = function() { return foo; }; // OK, all references are referring to never modified variables.
a();
}
//... no modifications of foo after this loop ...