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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:44:41+00:00 2026-06-07T03:44:41+00:00

I want to use Backbone.js for some event handling things, but I am not

  • 0

I want to use Backbone.js for some event handling things, but I am not confident about cyclical references & memory management. Let’s say I have some static event source called EventStation – so, at the start of the script I say:

var source = new EventSource();

source is meant to live for the life of page and that’s fine. Now, I also have an event consumer:

var EventConsumer = Backbone.Model.extend({
    initialize: function(params) {
        source.on("some_event",this.onSomeEvent,this);
    }
});

function later() {
    var consumer = new EventConsumer();

    // consumer now gets leaked... (I think)
}

I call later() at some point – and at the end, I no longer have any access to consumer, except if I go digging around through the internals of source. I think I need to add some new function to EventConsumer, like

cleanup: function() {
    source.off("some_event",this.onSomeEvent,this);
}

And then call that at the end of later().

This seems… not as clean as I would like it. Is there some way to do this better? Would this handle differently if I was using DOM events?

  • 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-07T03:44:42+00:00Added an answer on June 7, 2026 at 3:44 am

    Read this:

    http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/

    While it specifically talks about views, it applies to any event binding object.

    Also this:

    Backbone.js : repopulate or recreate the view?

    Johnny Oshika’s idea for managing event binding and unbinding with his “bindTo” method and “unbindAll” method are brilliant. I highly recommend using these methods in an object that manages your events for you.

    If you would like an implementation of this, I have it built in to my Backbone.Marionette framework, here:

    https://github.com/derickbailey/backbone.marionette/blob/master/src/backbone.marionette.bindto.js

    This code is MIT licensed open source, so you’re free to copy it and use it wherever you want… no requirement to use Marionette just to get this functionality.

    To use the BindTo object, you extend it in to your own object:

    
    var source = _.extend({}, Backbone.Marionette.BindTo);
    

    or use it as a prototype:

    
    var source = Object.create(Backbone.Marionette.BindTo);
    

    Then bind events passing the event source as the first parameter, with all the standard Backbone events args after that:

    
    source.bindTo(myObj, "some_event", this.doStuff, this);
    

    and to unbind everything,

    
    source.unbindAll();
    

    Documentation for my implementation can be found here:

    https://github.com/derickbailey/backbone.marionette/blob/master/docs/marionette.bindto.md

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

Sidebar

Related Questions

I don't want to override Backbone.sync() as some of my models will actually use
I am building a small administrative application, and I want to use Backbone.js on
i have a backbone.js api i want to use in an ExtJS app. Extjs
I want use BYTE_ORDER macro in my Xcode project but i can't because i
i want use some data from a website with web service. i have a
I want use JQuery mobile for the front-end of my mobile application, but I
I use localStorage to persist the data of my Backbone app. But every time
I have a web app that I want to use Backbone.js for. I have
I've just started using Backbone.js. I want to create a Collection and add some
I want use this 1 for using Bar code or QR code scanner. I

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.