Backbone: unable to populate Collection from raw data

Created on 14 Nov 2013  ·  2Comments  ·  Source: jashkenas/backbone

$(document).ready(function () {
  people = Backbone.Collection([
    {name: "Tim", age: 5},
    {name: "Ida", age: 26},
    {name: "Rob", age: 55}
  ]);
  alert(JSON.stringify(people));
});

causes

Uncaught exception: TypeError: 'this._reset' is not a function
Error thrown at line 23465, column 4 in <anonymous function: Backbone.Collection>(models, options) in http://127.0.0.1:8000/webapp/app.js:
    this._reset();
called from line 481, column 2 in <anonymous function>() in http://127.0.0.1:8000/:
    people = Backbone.Collection([

Backbone 1.1.0, Underscore 1.5.2 (the same with lodash).

Most helpful comment

You forgot to put new in front of Backbone.Collection.

All 2 comments

You forgot to put new in front of Backbone.Collection.

oops, silly me. i guess that's what happens when you code on several languages simultaneously -- you forget little but significant things every now and then.
thank you very much for your help.

Was this page helpful?
0 / 5 - 0 ratings