Is it possible to push functions to an array using var
instead of let
. The code I'm looking at is:
function slideRightLoop() {
let work = [];
for (var n = 1; n < 5; n++) {
let next = (n + 1 < 5) ? n + 1 : 1;
let el = document.querySelector(".position_" + n)[0];
var change = function change () {
el.classList.add("position" + next);
el.classList.remove("position_" + n);
}
work.push(change);
}
work.forEach(function (n) {
return n();
});
}