Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在将此ES6转换为ES5(包括扩展语法)时遇到问题_Javascript_Ecmascript 6_Ecmascript 5 - Fatal编程技术网

Javascript 在将此ES6转换为ES5(包括扩展语法)时遇到问题

Javascript 在将此ES6转换为ES5(包括扩展语法)时遇到问题,javascript,ecmascript-6,ecmascript-5,Javascript,Ecmascript 6,Ecmascript 5,在学习英语的同时,我正在尝试将以下内容翻译成ES5: const transitionendFn = ()=> { [...this.slider].forEach((el)=> el.className = 'item'); selectedEl.classList.add('active'); this.isAnimating = false } ES5: 我不明白传播的部分 此.slider包含以下内容: 感谢您对更正此代码的任何帮助 我的翻译中出现

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

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

我不明白传播的部分

此.slider
包含以下内容:

感谢您对更正此代码的任何帮助

我的翻译中出现“
TypeError
el
未定义”。

请注意:

  • 箭头函数没有此绑定。传统函数(ES5中唯一可用的函数)会这样做,因此必须将其绑定到所需的值
  • ES5没有
    const
    变量。只有
    var
  • ES5没有iterable对象。我假设
    这个.slider
    类似于数组
那么翻译应该是这样的

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

[…this.slider].forEach
可以翻译为
Array.prototype.forEach.call(this.slider,
[…foo]
习惯用法是将类似数组的对象或iterable转换为数组的一种方法。
[…this.slider]
大致等同于
Array.from(this.slider)
此.滑块应转换为数组,因为它在此处是可编辑的(可能是数组,也可能不是数组).ES5没有
const
@torazaburo只是易懂的,不是任意的数组喜欢。只有
array。从
处理数组喜欢。谢谢@Oriol和所有参与的人,我正在阅读所有的建议,这么多的信息要在这么短的时间内学习。很有效。
var transitionendFn = function() {
  [].forEach.call(this.slider, function(el) {
    return el.className = 'item';
  });
  selectedEl.classList.add('active');
  this.isAnimating = false;
}.bind(this);