📜  类关键字 es6 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:18.199000             🧑  作者: Mango

代码示例3
class Polygon {
  constructor(...sides) {
    this.sides = sides;
  }
  // Method
  *getSides() {
    for(const side of this.sides){
      yield side;
    }
  }
}

const pentagon = new Polygon(1,2,3,4,5);

console.log([...pentagon.getSides()]); // [1,2,3,4,5]