Search code examples
javascriptbackbone.js

Is viewInstance.undelegateEvents() the same as $(this.el).unbind()?


Is viewInstance.undelegateEvents() the same as jQuery's $(this.el).unbind()?

Do they function the same way, as in removing the events from the view?


Solution

  • From http://backbonejs.org/docs/backbone.html#section-131

        undelegateEvents: function() {
          this.$el.unbind('.delegateEvents' + this.cid);
        },
    

    So, they are nearly identical. But the undelegateEvents method scopes the undelegation to the events that the backbone view had explicitly set up with the delegateEvents method, using the declarative events configuration on the view.