Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
 )
like image 232
Miroslav Trninic Avatar asked Jun 22 '13 13:06

Miroslav Trninic


1 Answers

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.

like image 150
mu is too short Avatar answered Oct 10 '22 01:10

mu is too short