Miroslav Trninic
Miroslav Trninic

Reputation: 3455

Bind with coffeescript

How can I call native bind method of function-object with coffeescript ? This is the example of what I am trying to achieve:

window.addEventListener("load",function(e){
    this._filter(true);
    }.bind(this);
 )

Upvotes: 10

Views: 11217

Answers (1)

mu is too short
mu is too short

Reputation: 434745

Just add some parentheses around the function so that you can .bind the right thing:

window.addEventListener('load', ((e) ->
    this._filter(true)
).bind(this))

That will use the native bind method instead of the usual var _this = this trickery that CoffeeScript's => uses.

Upvotes: 14

Related Questions