Bind with coffeescript

10,951

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.

Share:
10,951

Related videos on Youtube

Miroslav Trninic
Author by

Miroslav Trninic

Java,Spring, Spring Boot, Domain Driven Design, Vim,Linux cycling, swiming, skiing, hiking, Jimi Hendrix

Updated on September 15, 2022

Comments

  • Miroslav Trninic
    Miroslav Trninic over 1 year

    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);
     )