Node Creating new object from inside class method


In one of my class static methods I have to create a new instance of the same class.

class User {
  static find() {
    const newUser = new this(); // new static(); in PHP
  }

}

The example above works but I got linting error:

“new” operators should be used with functions

Now, I’m wondering what’s the correct way to do it?

Tried new this.constructor() but it’s returning a function not an object.

#php #node-js

8 Likes2.25 GEEK