Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
 )
share|improve this question

2 Answers 2

up vote 5 down vote accepted

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|improve this answer
    
thanks, it works great now –  carousel Jun 22 '13 at 17:31

I think this is what you're trying to achieve:

window.addEventListener 'load', (e) => @_filter(true)
share|improve this answer
    
Looks good, but doesn't work. Converts into: window.addEventListener('load', (function(_this) { return function(e) { return _this._filter(true); }; })(this)); –  Orwellophile Mar 29 at 9:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.