【问题标题】:Populating an array (defined in an object) with objects用对象填充数组(在对象中定义)
【发布时间】:2013-06-30 06:10:57
【问题描述】:

我已经创建了一个对象来填充一个数组并在另一个对象中定义一个数组:

    var ListEntry = function (name, code, order) {
        this.name = name;
        this.code = code;
        this.order = order;
    }

    var myObject = Class.extend({
        list: new Array()
    })

稍后将使用以下数据填充:

    var ListEntry = new ListEntry(cell[0], cell[1], cell[2]);
    this.list.push(ListEntry);

这会抛出一个 typeError: ListEntry is not a constructor,当尝试创建新对象时。

任何帮助表示赞赏!

【问题讨论】:

  • 您可能应该考虑将ListEntry 的实例命名为ListEntry 以外的名称...

标签: javascript arrays object typeerror


【解决方案1】:
var listEntry = new ListEntry(cell[0], cell[1], cell[2]);
this.list.push(listEntry);

【讨论】:

  • 谢谢!像魅力一样工作
猜你喜欢
  • 1970-01-01
  • 2020-06-28
  • 2018-11-14
  • 2013-03-10
  • 1970-01-01
  • 2022-01-24
  • 2016-01-19
  • 2022-08-02
  • 2019-01-15
相关资源
最近更新 更多