Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:09:18+00:00 2026-05-31T09:09:18+00:00

I have a web application that is currently using backbone.js 0.5.3 with backbone local

  • 0

I have a web application that is currently using backbone.js 0.5.3 with backbone local storage adapter 1, underscore.js 1.2.2 and jquery mobile 1.0.1.
I wanted to upgrade my version of backbone and underscore, however when I upgrade my version of underscore (1.2.2 to 1.3.1) I get an error in backbone.js (I’ll detail the error below). I tried just upgrading underscore and upgrading both underscore and backbone.js and I still get the error. I don’t see any breaking changes in the changelog for underscore, but maybe I’m missing something.

Here are the details of the javascript error that I’m getting in backbone.js, the error message is “this.model is not a constructor“ in firebug or “Uncaught TypeError: undefined is not a function” in chrome. The error is thrown in the _prepareModel method of the backbone.collection which is called by its add method which is triggered off based on a fetch call in my code (which is pulling from local storage not the server). What I can see is that “model” is undefined (I think it’s supposed to be a function) in the method and that’s why it’s throwing the error, I’m just not quite sure what to do about it.

Here’s the code of the _prepareModel method

    _prepareModel: function(model, options) {
  if (!(model instanceof Backbone.Model)) {
    var attrs = model;
    options.collection = this;
    model = new this.model(attrs, options);
    if (!model._validate(model.attributes, options)) model = false;
  } else if (!model.collection) {
    model.collection = this;
  }
  return model;
},

I don’t really have much of my own code that I can post, since I’m just calling fetch on a collection.

Thanks

EDIT

Here’s some code that reproduces the issue I’m talking about. If i use underscore.js version 1.2.2 it works fine, if i swap it for 1.3.1 it throws an error.

var YM = YM || {};
YM.Holidays = YM.Holidays || {};

YM.Holidays = {

Holiday: Backbone.Model.extend({
    fDate: null,
    Description: null,
}),

HolidayView: Backbone.View.extend({

    tagName: 'li',

holidayTemplate: null,

initialize: function () {
    this.holidayTemplate = _.template($('#holiday-template').html());
},

render: function () {
    $(this.el).html(this.holidayTemplate(this.model.toJSON()));
    return this;
 },
}),

Holidays: Backbone.Collection.extend({
   model: YM.Holidays.Holiday
}),

HolidayListView: Backbone.View.extend({

el: 'body',

initialize: function () {
    this.collection = YM.holidays;
},

render: function () {
    var $holidayList = $('#ulHolidays');
    _.each(this.collection.models, function (holiday) {
        var view = new YM.Holidays.HolidayView({  model: holiday});
        $holidayList.append(view.render().el);
    }, this); 
 }
})

};


$(function () {

var holidays = [ {fDate: '1/1/2012', Description: 'New Years'}
                        , {fDate: '1/16/2012', Description: 'ML King Day'}
                        , {fDate: '2/20/2012', Description: 'Presidents Day'}];
 YM.holidays = new YM.Holidays.Holidays();
 YM.holidayListView = new YM.Holidays.HolidayListView();
 YM.holidays.add(holidays);
 YM.holidayListView.render();
 });

EDIT 2

It gets a bit stranger, it seems like the issue is somehow related to jquery mobile, I plan on looking into that a little more. In the meantime here are two jsfiddles the only difference between them being which version of underscore they use.

http://jsfiddle.net/KDMcd/ – underscore 1.2.2 works
http://jsfiddle.net/hnGAA/ -underscore 1.3.1 doesn’t work

EDIT 3

Thanks, that works in my test example and I’m going to try that in my actually project. Do you have any idea why it’s necessary to explicitly set the model later? Because the way I was doing it seems to be the way it’s supposed to be done based on the documentation. Also any idea what changed in underscore that this is now necessary? Thanks

OK, I was able to fix the issue based on ryanmarc answer, what I ended up doing is explicitly setting the backbone’s collection’s models in the initialize method so instead of

    Holidays:  Backbone.Collection.extend({  
    model: YM.Holidays.Holiday
    }),

I’m doing this

     Holidays: Backbone.Collection.extend({  

     inititlaize: function () 
     { 
        this.model = YM.Holidays.Holiday;
      }
   }),

Another strange thing is using the same code and libraries if I switch the html so that I’m rendering the list in a plain div as opposed to a JQM page it also doesn’t throw that error (it renders the list twice for some reason, but since I’m not really trying to do that I haven’t looked into why).
For example if instead of the following markup

<div data-role="page" id="Holidays">
  <div data-role="header">
  <h1>Holidays</h1>
  </div>
  <div data-role="content">
          <ul data-role="listview" data-inset="true" id="ulHolidays">
        </ul>
  </div>
  <div data-role="footer">
        <h3>Footer</h3>
  </div>
  </div> 

I use this mark up

  <div>
   <ul data-role="listview" data-inset="true" id="ulHolidays"></ul>
  </div>

I don’t get the error (though it renders twice, but that’s probably not related). Anybody have any ideas or insights as to what is going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:09:20+00:00Added an answer on May 31, 2026 at 9:09 am

    it works fine with this small change: http://jsfiddle.net/hnGAA/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a web-application that implements a rudimentary form of ACL using UNIONs
I currently have a web application that I would like to scale out using
I have a web application that currently sends emails. At the time my web
I have a web application that's branded according to the user that's currently logged
I have a web application that can load plugins through reflection. It currently uses
Currently I have an application that receives an uploaded file from my web application.
I'm currently writing a web application that have about 6-12 pages. On each one
I have a web application that uses the current version of JQuery that needs
I have a web application that talks to R using plr when doing adaptive
I have a mobile web application that uses the Javascript SDK to connect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.