我正在尝试根据ES类参数创建一个数组,但是却得到一个空数组,为什么?

问题描述

在此创建ES类的值为“ sideLength”的数组的场景中考虑此代码,并在此ES类中考虑“ sides”的时间,但是我一直在获取一个空数组!这是codepen link

class ShapeNew {
  constructor(name,sides,sideLength) {
    this.name = name;
    this.sides = sides;
    this.sideLength = sideLength;
  }
  tryArray() {
    let sides_array = [];
    for (let i = 0; i < this.sides; i++) {
      sides_array = sides_array.push(this.sideLength);
    }
    return sides_array;
  }
  newPerimeter() {
    let peri = this.tryArray();
    console.log(peri.reduce((sum,accum) => sum + accum));
  }
}
let new_square = new ShapeNew("square",4,5);
new_square.newPerimeter();

我要做的就是将4转换为[5,5,5],我该怎么做?

预先感谢您对此进行调查,非常感谢:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)