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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:18:10+00:00 2026-06-14T15:18:10+00:00

I am working on a Backbone application. I created base view which has a

  • 0

I am working on a Backbone application. I created base view which has a destroy method and all other views extend it.

When destroying a view instance I want to make sure that if the view has a model or a collection I am unbinding any events it was listening to.

Assuming I am using underscores’s _.bindAll in the view’s initialize, will the off
statement below remove the references.

var DocumentRow = Backbone.View.extend({

  initialize: function() {
      _.bindAll( this );

     this.model.on('change', this.render);
  },


  destroy : function() {
      // Will this work?
      this.model.off(null, null, this);

  }


});

or do I need to explicitly bind events like so

this.model.on('change', this.render, this);
  • 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-14T15:18:10+00:00Added an answer on June 14, 2026 at 3:18 pm

    this.model.on('change', this.render); will not work the way you want. You need to change it to this.model.on('change', this.render, this);

    If you look at the source for the on method (http://backbonejs.org/docs/backbone.html#section-18 ) it does not default your context variable to anything. So if you don’t set it, the call to off will not find the event bindings correctly.

    FWIW, I get tired of having to do corresponding on and off calls, so I wrote a plugin to handle a lot of it for me: https://github.com/marionettejs/backbone.eventbinder

    You can use it like this, and not have to worry about getting the right context or anything else.

    
    var DocumentRow = Backbone.View.extend({
    
      initialize: function() {
         this.eb = new Backbone.EventBinder();
         this.eb.bindTo(this.model, 'change', this.render);
      },
    
    
      destroy : function() {
          this.eb.unbindAll();
      }
    
    });
    

    The real benefit in this is not having to call off for every on. you only need to make one call to unbindAll and it will unbind all of the events that are stored in the event binder instance.

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

Sidebar

Related Questions

I am working on a backbone.js application with rails api which provides the json
I'm working on a Backbone.View which should render a collection as a scrollable list.
I'm working on a application which has sidebar on the right side. That displays
I'm working on a backbone application. I've structured my models + collections + views
I am working on a backbone.js application with rails api which provides the json
We're designing a backbone application, in which each server-side collection has the potential to
I'm working on a backbone application on Google Chrome (v19.0.1084.56) and when I am
I am working on converting a Backbone application into an Ember application using Ember
I'm working on a graph visuzalization using D3 in a backbone view. I allow
Currently I'm working on a Server-Client system which will be the backbone of my

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.