📜  javascript mdn 中的类 - Javascript 代码示例

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

代码示例1
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]