我正在尝试在javavscript中创建一个对象,然后在另一个文件中对其进行初始化。即使一切看起来对我来说,我似乎都不明白问题所在。下面是我的代码
class Account {
constructor(account_id, official_name, name, subtype, type, balances) {
this.account_id = account_id;
this.official_name = official_name;
this.name = name;
this.subtype = subtype;
this.type = type;
this.balances = balances;
}
}
module.exports = Account;
这就是我的创建方式:
const { Account } = require('../../model/account');
const {
account_id, name, official_name, subtype, type, balances
} = accounts[key];
const account = new Account(account_id, official_name, name, subtype, type, balances);
和错误:
TypeError: Account is not a constructor
我在这里想念什么?
所以正如Patrick Roberts在评论中解释的那样
module.exports.Account = Account
const { Account } = require('../../model/account')
或
module.exports = Account
const Account = require('../../model/account')