Search code examples
javascriptcoffeescriptcallbind

Binding and calling functions in coffee


Using bind and call with coffee

function ping(){
    console.log(that);
}.bind(that);

Before you suggest it, I know you can use fat arrows to scope like this, but what happens when you want to pass another variable into the function when using coffee. I don't want to pass this I want to pass that.


Solution

  • If you want to do that or call other methods on a Function (such as property in Ember), just add some parentheses:

    ping = (-> console.log(that)).bind(that)
    

    Demo