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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:52:05+00:00 2026-06-17T15:52:05+00:00

When you look into the source code of Backbone.js, version 0.9.2, there is _onModelEvent:

  • 0

When you look into the source code of Backbone.js, version 0.9.2, there is

“_onModelEvent”:

This method is responsible of forwarding events from the model to the collection (bubbling up).

So when you change something in a model which is part of a collection (with “set”), there is a change event, and because (in the add method) the _onModelEvent method was bound to the model (“all”), this method gets called.

I also see, that there is a destroy method, which triggers a “destroy” event.

But why does the author (in the first line of the _onModelEvent) check, if the event name is “add” or “remove”. Normally there is no “add” event on the model?

I do not understand this.

Can somebody explain it to me?

Thanks in advance

_onModelEvent: function(event, model, collection, options) {
  if ((event == 'add' || event == 'remove') && collection != this) return;
  • 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-17T15:52:06+00:00Added an answer on June 17, 2026 at 3:52 pm

    With Backbone you can create nested model structures and collections. So you can create a collection where the model is a collection. That is way the check in place:

    So from the annotated source:

    _onModelEvent:

    Internal method called every time a model in the set fires an event.
    Sets need to update their indexes when models change ids. All other
    events simply proxy through. “add” and “remove” events that originate
    in other collections are ignored.

    So if you have a collection as a model. It won’t delegate the add or remove event if items were added/removed to/from the child collections because in that case only the child collection is changed and not the parent.

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

Sidebar

Related Questions

Take a look into source code . There could be valid reasons behind that,
I've taken a look into OpenJDK source code of CopyOnWriteArrayList and it seems that
I'm debugging into the .NET Framework source code to look for a bug in
I need to look into the CCTray source code. I can only find the
As I look into documentation of GKScore and GKLeaderboard, there is no way to
I was taking a look on the jquery.validate plugin source code , to check
I have used file_get_contents() to basically get the source code of a site into
I was advised to look here: http://exampledepot.com/egs/javax.crypto/DesFile.html for the source code of encryption/decryption using
I was reading the source code of backbone today to try and learn how
I am learning WPF and wanted to look at source code to some good

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.