sudheerj / ECMAScript-features

ECMAScript features cheatsheet
875 stars 246 forks source link

Class example is not appropriate #25

Closed archersunx closed 1 month ago

archersunx commented 1 month ago

This Class example has a problem,setting area would case infinite loop。I know it's just an example,but it may confuse someone new to the language

class Square {
  constructor(length) {
    this.length = length;
  }

  get area() {
    return this.length * this.length;
  }

  set area(value) {
    this.area = value;
  }
}
sudheerj commented 1 month ago

@archersunx Thanks for notifying this bug. Fixed it.