有人能解释一下为什么第一个导出会抛出“is not a constructor”错误,而第二个导出可以工作吗?
// Throws a `is not a constructor` error
module.exports = {
Person: function () {
constructor()
{
this.firstname;
this.lastname;
}
}
}
// Works
class Person {
constructor()
{
this.firstname = '';
this.lastname = '';
}
}
module.exports = Person;
// Usage:
const Person = require("person");
let person = new Person();