quick-lint-js

Find bugs in JavaScript programs.

E0155: cannot reference private variables without object; use 'this.'

Classes can contain private properties. Their names start with #. It is a syntax error to use a private property without an object:

class Account {
  #email;
  #passwordHash;

  changePassword(newPassword) {
    #passwordHash = hashPassword(newPassword);
  }

  async save(db) {
    await db.saveAccount({
      email: #email,
      passwordHash: #passwordHash,
    });
  }
}

To fix this error, write this. before the use of the private property:

class Account {
  #email;
  #passwordHash;

  changePassword(newPassword) {
    this.#passwordHash = hashPassword(newPassword);
  }

  async save(db) {
    await db.saveAccount({
      email: this.#email,
      passwordHash: this.#passwordHash,
    });
  }
}

Documentation for other errors