class Example {
constructor(id) {
this.id = this.getId();
}
getId() {
inquirer
.prompt({
message: "Enter id?",
type: "input",
name: "employeesId",
})
.then((answer) => (this.id = answer.employeesId));
}
}
const testExample = new Example();
testExample.getId()
console.log(testExample.id); // <-- expected to log the id after user has entered it, instead returns undefined
所以我是 OOP 的新手,只是想了解为什么这不起作用,任何帮助将不胜感激。
也将高度赞赏与解释的工作。
提前致谢。