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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:39:18+00:00 2026-06-04T17:39:18+00:00

Is it a bad practice to call undelegateEvents() in the view remove() method? Why

  • 0

Is it a bad practice to call undelegateEvents() in the view remove() method? Why wasn’t it included by default by the backbone guys?

I realized I am falling into so many binding issues, when simply reinitializing a view variable. Although undelegateEvents() is being called automatically when a new view is created, it is trying to undelegate events for the newly instantiated view, not the previous one. Therefore, unless manually calling it every time, ghost event callbacks remain alive and screw up my apps.

What’s the best way to handle 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-04T17:39:21+00:00Added an answer on June 4, 2026 at 5:39 pm

    Is it a bad practice to call undelegateEvents() in the view remove() method?

    It’s not necessary unless you’re implementing your own remove() and you don’t call Backbone.View.remove() or this.$el.remove(). That’s if you’re using jQuery, at least. Calling remove() on a Backbone view will call jQuery.remove() which will remove all of the DOM event listeners anyway.

    I realized I am falling into so many binding issues, when simply reinitializing a view variable.

    A lot of people seem to use Backbone.Events like it’s some kind of magic that they don’t need to clean up after, e.g.:

    var View = Backbone.View.extend( {
    
      initialize : function ( options ) {
    
        // `on()` or `bind()`
    
        this.model.on( 'something', this.render, this );
    
      }
    
    } );
    

    See my answer on Delegating events to a parent view in Backbone

    Is it possible that the ghost event issues you’re experiencing are with Backbone events and not DOM events?

    If you keep the model object around but want to get rid of that view object or its Backbone event registrations, you have to do view.model.off( null, null, this );. You have to unbind the events that you’ve registered on any external objects. If you want, you could override Backbone.View.remove() and do it there, but by default that method is just shorthand for view.$el.remove().

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

Sidebar

Related Questions

I've read that it is bad practice to call strlen() in my for loop
In C, it is considered bad practice to call strlen like this: for (
Is it considered bad practice to have multiple try's in one method and structure
Is it a bad coding practice to call the exit() function in Python repeatedly?
I know it's a bad practice to use database in the view. However, I'm
My General Question is : Is it inefficient/bad practice to call preparedStatement.executeBatch() if there's
Is the following code bad practice? for i in some_values: do_whatever(i) do_more_things(i) Somehow, it
I know this is bad practice. Don't write code like this if at all
Would you consider it bad practice to store various user data in a database
Is it a bad practice to mix GET and POST? (note this is in

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.