将此 ES6 转换为 ES5 时遇到问题,包括扩展语法

Having trouble translating this ES6 to ES5 including spread syntax

我正在尝试将以下内容翻译成 ES5,同时学习这门语言:

const transitionendFn = ()=> {
    [...this.slider].forEach((el)=> el.className = 'item');
    selectedEl.classList.add('active');
    this.isAnimating = false
}

ES5:

const transitionendFn = function() {
    [].concat(this.slider).
        forEach(function (el) {
            return el.className = 'item';
        });
    selectedEl.classList.add('active');
    this.isAnimating = false
}

展开部分没看懂

this.slider 包含以下内容:

感谢任何纠正此代码的帮助。

我的翻译得到“TypeError: el is undefined”。

请注意:

  • 箭头函数没有 this 绑定。传统函数(ES5 中唯一可用的函数)可以,因此您必须将其绑定到所需的值。
  • ES5 没有 const 变量。只有 var 个。
  • ES5 没有可迭代对象。我假设 this.slider 是类似数组的。

那么翻译应该是这样的

var transitionendFn = function() {
  [].forEach.call(this.slider, function(el) {
    return el.className = 'item';
  });
  selectedEl.classList.add('active');
  this.isAnimating = false;
}.bind(this);