79399988

Date: 2025-01-30 13:05:00
Score: 0.5
Natty:
Report link

The other answers here work, but are not good. Referencing the class name from within the class is something you shouldn't do. What if the class name changes? what if you are working with inheritance? It will be broken. use this.constructor to get to the the static methods on a given instance

class User {
  constructor(fields) {
   this.email = fields.email;
   this.name = fields.name;
  }

  static async exist(email) {
    return setTimeout(function() {
      return userEmails.includes(email)
    }, 2000)
  }

  async storeEmail() {
    let userExist = await this.constructor.exist(this.email)

    if (userExist) {
      console.log('User exist')
    } else {
      users.push(this.email)
      console.log(userEmails)
    }
  }
};
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: wmantly