为什么backbonejs 在模型中创建大量集合,我不知道它什么时候停止。
以http://backbonetutorials.com/what-is-a-collection/中的这个例子为例。如果您查看控制台并继续打开 d 对象,则其中总会有一个“集合”对象,它只是再次重复相同的对象。
我不知道这是一个错误还是什么,但我不太确定这是正常的。
有人请赐教。谢谢。
var Song = Backbone.Model.extend({
defaults: {
name: "Not specified",
artist: "Not specified"
},
initialize: function(){
console.log("Music is the answer");
}
});
var Album = Backbone.Collection.extend({
model: Song
});
var song1 = new Song({ name: "How Bizarre", artist: "OMC" });
var song2 = new Song({ name: "Sexual Healing", artist: "Marvin Gaye" });
var song3 = new Song({ name: "Talk It Over In Bed", artist: "OMC" });
var myAlbum = new Album([ song1, song2, song3]);
console.log( myAlbum.models ); // [song1, song2, song3]
@ryan
是的,我知道模型可能包含对其集合的引用。但是有这种似乎没有尽头的链接对象有点奇怪。对象树是这样的:
[d, d ,d]
0 > d
> collection
> models
0 > d
> collection
> models
0 > d
> collection
> models
0 > d
...
keeps on and on and on
为什么会这样?