Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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]
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #classes #javascript #mdn
ADD COMMENT
Topic
Name
3+9 =