1

I want to create objects of subclasses from a parent class's static method.

    class QueryBuilder {
        constructor() {
            this.table = new.target.name;
        }

        static find(id) {
            return new Promise((resolve, reject) => {
                connection.query('SELECT * FROM users WHERE id = ?', [id], (err, result) => {
                    if(err) {
                        return reject(result);
                    } else {
                        return resolve(err);
                    }
                });
            });
        }
    }
    class users extends QueryBuilder {
        constructor(data) {
            super();
        }
    }
users.find(1).then(data => {
console.log(data) // I would like to have an instance of users class
});

The above code is working fine I am getting the user data then arrow function but I want there is an instance of users class.

Here is a the same question asked for PHP.

Amarjit Singh
  • 2,068
  • 19
  • 52

0 Answers0