gpt4 book ai didi

backbone.js - "Uncaught TypeError: undefined is not a function"初始化 Backbone 集合

转载 作者:行者123 更新时间:2023-12-04 01:47:11 24 4
gpt4 key购买 nike

我有一个 Backbone 集合,如下所示:

var FooCollection = Backbone.Collection.extend({
model:Foo,

initialize: function (attributes, options) {
this.barId = options.barId;
}
});

var Foo = Backbone.Model.extend({});

当我尝试初始化它时,我在 _prepareModel() 中得到“Uncaught TypeError: undefined is not a function” Backbone.Collection 的功能.

坏电话在 model = new this.model(attrs, options) .
// Prepare a model or hash of attributes to be added to this collection.
_prepareModel: function(model, options) {
options || (options = {});
if (!(model instanceof Model)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options); // <-- BLOWS UP HERE
if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},

当我通过 _prepareModel()在调试器中,它看起来像 this 的类型那时是 child , 和 this.model实际上是未定义的。

谁能告诉我我做错了什么?

最佳答案

在我的实际代码中 FooFooCollection 之后声明.没有意识到 Javascript 不支持前向声明。 【前台】

关于backbone.js - "Uncaught TypeError: undefined is not a function"初始化 Backbone 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14162605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com