Lorraine Bernard
Lorraine Bernard

Reputation: 13420

Event Binding in Backbone.Marionette context

I am wondering why _.bindAll(this, ['onSortRemove']); in the following code (1) rises the following error:

Uncaught TypeError: Object [object Window] has no method 'resetItemViewContainer'

To get things working I need to implement the following code _.bindAll(this);.

My question is: should _.bindAll(this, ['onSortRemove']); be enough? if not, why?


(1)

    initialize: function () {
        _.bindAll(this, ['onSortRemove']); // it does not work
        _.bindAll(this); // it works
     }

    onSortRemove: function () {
        setTimeout(this.render, 0);
    }

Upvotes: 0

Views: 609

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72878

Syntax error


initialize: function () {
  _.bindAll(this, 'onSortRemove'); // <- no array wrapper
}

The documentation's syntax of [*methodnames] is not saying "wrap this in an array". That's old-school documentation style to say "method names is optional, it can be zero or more arguments, comma-delimited".

Upvotes: 2

Related Questions