DEV Community

Discussion on: A super-easy way to determine 'this' in JavaScript

Collapse
 
efpage profile image
Eckehard

Nice tip, but how do you write classes without this? The book was written in 2008, hopefully things have changed since then.

class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}
Enter fullscreen mode Exit fullscreen mode

I totally agree that the inventors of Javascript had not their best day when they implemented "this", but in some cases it seems we cannot avoid this, and earlier or later you will get in trouble with this.