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 8033967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:52:13+00:00 2026-06-05T01:52:13+00:00

I have a Backbone collection jQuery -> class App.Collections.List extends Backbone.Collection model: App.Models.ListItem I

  • 0

I have a Backbone collection

jQuery ->
  class App.Collections.List extends Backbone.Collection
    model: App.Models.ListItem

I am trying to initialize the collection on page load:

var list = new App.Collections.List;
list.reset(<%= @data.to_json.html_safe %>)

This throws a JS error in the backbone lib.

Uncaught TypeError: undefined is not a function application.js:597
f.extend._prepareModel application.js:597
f.extend.add application.js:591
f.extend.reset application.js:595
(anonymous function)

However, if i change the code to:

var list = new Backbone.Collections;
list.reset(<%= @data.to_json.html_safe %>)

The reset works, and the collection is populated — thought the objects in the Collection don’t appear to know that they should be ListItem objects. Do I have to do something special to all a reset of my custom Collection?

  • 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-06-05T01:52:16+00:00Added an answer on June 5, 2026 at 1:52 am

    the _prepareModel stacktrace line gives a hint that you have your model declared after your collection.

    You most likely have your code set up like this:

    
      class App.Collections.List extends Backbone.Collection
        model: App.Models.ListItem
    
      class App.Models.ListItem extends Backbone.Model
    

    which is going to fail because ListItem is not yet declared when you try to use it in your collection’s model attribute. You are essentially setting the model attribute to undefined.

    You need to declare the model first:

    
      class App.Models.ListItem extends Backbone.Model
    
      class App.Collections.List extends Backbone.Collection
        model: App.Models.ListItem
    

    Note that this is not a limitation in CoffeeScript or Backbone. This is a JavaScript behavior caused by the use of object literals. The value of an object literal key/value pair is evaluated immediately, which means it must exist or it will be returned as undefined or some other error thrown.

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

Sidebar

Related Questions

I have a Backbone collection model (with sub-models as elements) and views to edit
I have a Backbone collection and when I add a new model to it
I have a Backbone View that has a Collection as its Model. If the
Here I have a Backbone.js Model - Contact and a Collection - Contacts with
How can i compare two collections in backbone? I have two collection 1C contains
Newbie backbone question: Context: Building a shopping list with backbone I have a model
I have the following Backbone.js model and collection: // Model lr.Event = Backbone.Model.extend({}); //
I have very simple backbone model and collection. I have a corresponding backbone.marionette.CollectionView and
I have a backbone collection and when I remove a model from the collection,
I have a backbone collection which has a bunch of models with date attributes

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.