[英]Having trouble translating this ES6 to ES5 including spread syntax
I am trying to translate the following into ES5, while learning the language: 我正在尝试将以下内容翻译成ES5,同时学习语言:
const transitionendFn = ()=> {
[...this.slider].forEach((el)=> el.className = 'item');
selectedEl.classList.add('active');
this.isAnimating = false
}
ES5: 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: this.slider
包含以下内容:
Any help correcting this code is appreciated. 任何纠正此代码的帮助表示赞赏。
I get “ TypeError
: el
is undefined” with my translation. 我的翻译得到“
TypeError
: el
is undefined”。
Be aware that: 意识到:
this
binding. this
绑定。 Traditional functions (the only kind available in ES5) do, so you will have to bind it to the desired value. const
variables. const
变量。 Only var
ones. var
。 this.slider
is array-like. this.slider
是类似数组的。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.