I am trying to translate the following into ES5, while learning the language:
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
}
I don’t understand the spread part.
this.slider
contains the following:
Any help correcting this code is appreciated.
I get “TypeError
: el
is undefined” with my translation.
Be aware that:
this
binding. Traditional functions (the only kind available in ES5) do, so you will have to bind it to the desired value.const
variables. Only var
ones.this.slider
is array-like.Then the translation would be something like
var transitionendFn = function() {
[].forEach.call(this.slider, function(el) {
return el.className = 'item';
});
selectedEl.classList.add('active');
this.isAnimating = false;
}.bind(this);