DEV Community


Posted on

Is declaring helper variables which are simply removal of `this` bad practice?

Hi there, I'm newbie for and this is my first post.

Our company has a convention to declare helper variables which are simply removal of this like the following.

export class SampleClass {
  constructor() {
    // this is a constructor

  get sampleGetter() {
    // return something

  sampleMethod() {
    // What do you think about the following?
    const sampleGetter = this.sampleGetter;

    // do something

I was thinking that it's efficient when the variables are used multiple times.
However, I've been recently pointed out that it's premature optimaization and just adds a tiny bit of complexity with no clarity.

What do you think? I'd like to hear your opnions.

Top comments (0)