Take a look at LibraryPreps.prototype and you will see where you are mistaken. First of all, your real code should look bigger, or you will get ReferenceError s:
var LibraryPreps = (function () { ... })(); var LibraryPrep = (function () { ... })();
When the anonymous function executing LibraryPreps is executed, LibraryPrep will be undefined because it has not been assigned a value until a later time. If you do this:
var LibraryPreps = (function () { return Backbone.Collection.extend({ model: LibraryPrep,
you will see that LibraryPreps.prototype.model is undefined in the console. Demo: http://jsfiddle.net/ambiguous/y8cja/
Calling Backbone.Collection.extend (with or without an anonymous self-learning shell of functions) causes LibraryPrep evaluate when extend called, so you create a "class" collection with an undefined model . Then, inside the Backbone, it will search for the idAttribute the collection model and you will get your error.
Correct the order of your definitions so that everything is defined before they are used:
var LibraryPrep = (function () { ... })(); var LibraryPreps = (function () { ... })();
and you will get better results.
In the Loamhoof comments , your code works fine with the current version of Backbone (1.0.0), and I cannot find this:
this._idAttr || (this._idAttr = this.model.prototype.idAttribute);
anywhere in the source 1.0.0. Presumably you are using an older version of Backbone, the Collection#add method should know the idAttribute property of your model.
mu is too short
source share