对象不是构造函数

时间:2019-01-10 21:12:04

标签: javascript node.js module commonjs

我试图在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

我在这里想念什么?

1 个答案:

答案 0 :(得分:0)

正如帕特里克·罗伯茨在评论中解释的那样,

class SomeCollectionViewCell: UICollectionViewCell {

    ...

    private let normalCellWidth:  CGFloat = 150
    private let focusedCellWidth: CGFloat = 250

    override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        super.didUpdateFocus(in: context, with: coordinator)

        let scaleXValue: CGFloat = focusedCellWidth/normalCellWidth
        let scaleFactor = self.isFocused ? CGAffineTransform(scaleX: scaleXValue, y: 1.0): CGAffineTransform(scaleX: 1.0, y: 1.0)
        self.transform = scaleFactor
    }

    ...

}
module.exports.Account = Account

const { Account } = require('../../model/account')
module.exports = Account
相关问题