Olivier
Olivier

Reputation: 3471

Underscore _.bind() issue with nested function calls

After using _.bindAll('addOne'), the addOnemethod does get a correct this but it somehow breaks function calls on other objects inside this "bound" method :

/**
 * Add an element to the list
 */
addOne: function(tag) {

    // scope of this is correct
    var newClass = App.getViewClass('myClass')(someOptions) <-- scope inside App::getViewClass is wrong! overriden by current this

}

Any ideas on how i could somehow restore normal behavior?

Upvotes: 1

Views: 237

Answers (1)

Olivier
Olivier

Reputation: 3471

Needed to wrap my getter :

var myObject = new (App.getModelClass(model))(data);

As i got incorrect scope with :

var myObject = new App.getModelClass(model)(data);

Upvotes: 1

Related Questions