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

  • Home
  • SEARCH
  • 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 8442999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:00:17+00:00 2026-06-10T09:00:17+00:00

I want to replace the Backbone.Events system from some sub object with the one

  • 0

I want to replace the Backbone.Events system from some sub object with the one of my parent object. Example:

// initialize function of the repository object
initialize: function() {
        var users = new Backbone.Collection();
        
        // we save a reference of our event system in ourEvents object
        var ourEvents = {};
        ourEvents.on = this.on;
        ourEvents.off = this.off;
        ourEvents.trigger = this.trigger;
        ourEvents.bind = this.bind;
        ourEvents.unbind = this.unbind;

        // now we overwrite events in users.collection with our one
        _.extend(users, ourEvents);

        // now we listen on the test event over this
        this.on('test', function() { alert('yiha'); });

        // but triggering over users works too!
        users.trigger('test');
}

As you we now got some sort of one to many event system. One listener and many object which could fire events.

This helps me when working with different Backbone.Collections or Backbone.Models which got the same view system as front-end.

As you see the solution is not yet optimal.

Is there a shorter way to overwrite the event system ?

UPDATE:
So I studied the Backbone Source code and found out that Backbone.Events saves a callback list under:
this._callback. This should at least theoretically work:

this.users._callbacks = this._callbacks = {};
  • 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-10T09:00:19+00:00Added an answer on June 10, 2026 at 9:00 am

    Clean Backbone way of doing that would be to bind the events on the collection rather then trying to copy them for some reason from an object

    // initialize function of the repository object
    initialize: function() {
            var users = new Backbone.Collection();
    
            users.on('on', this.on, this);
            users.on('off', this.off, this); // third parameter to set context of method to the current view
            // ...and so on
            // you were listening here on the current view but triggering later on collection - this would never work
            users.trigger('on'); // would call the this.on method in the context of current view
            // if this method would have been triggered from inside of the users collection it would still trigger the desired method inside of this view
    }
    

    A tip – never touch and take advantage of methods and variables preceded with an underscore – these are meant to be private APIs and properties and might change at any point in time with the next release as only public methods/properties are guaranteed not to change between releases. I believe you were trying here a bit to overcomplicate and looking at some of the errors you’v made you’ve been trying bit too hard and in too many diferent ways 🙂 Always try to keep things simple

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

Sidebar

Related Questions

I want to replace child elements from one tree to another , based on
I want to replace some headers by images, so I would have nice font.For
I want to replace each character of a string by a different one, shifted
I want replace default close button in Fancybox 1.3.4 with custom one. I've changed
I want to replace some characters with others i have asked a question like
i want Replace بازي to بازی var List = (from darkhast in Tbl_Darkhast.Where(d =>
I want replace a(or each) element(number) instead another element(number) in a class while running
i want to replace the bottom panel where we show Next,Back buttons with a
I want to replace part of the following html text (excerpt of a huge
I want to replace a regex with '*', but only if the regex is

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.