DEV Community

Discussion on: Destructuring the 'this' object in JavaScript

Collapse
 
blindfish3 profile image
Ben Calder

I've considered this myself. It can definitely make code feel more readable but there are a couple of drawbacks:

  • You can't easily distinguish class members from temporary variables declared in methods
  • IIRC you can't always assign a value to a destructured variable, so then have to remember to use this.myVar = newValue
Collapse
 
hunterheston profile image
Hunter Heston

I'm used to representing members with a _ at the end of their name, something like this.message_. I'm also used writing c++ which does not require the use of this to access members. So I have some biases that don't necessarily fit with the normal conventions or language JavaScript 🤷‍♂️.

And you're right there is some nuance for value types and reference types. I'm updating the post now to clarify them!