Because you first call is create (in super) and only after you set this.table.
class Model {
constructor(table) {
// table is undefined, call create..
this.table = table;
this.create();
}
create() {
let queryString = `INSERT INTO ${this.table}`;
console.log(queryString);
}
}
class UsersModel extends Model {
constructor(table) {
// table is undefined, call super..
super(table);
this.table = "users";
// here you already have table name, so create works with it
this.create();
}
}
new UsersModel();
CLICK HERE to find out more related problems solutions.