Answers for "classes in javascript mdn"

0

classes in javascript mdn

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]
Posted by: Guest on October-01-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language