jashkenas/coffee-script — Issue #1936: Provide "@(...) -> ..." bound closure
Author: krestenkrab
Created: 2011-12-16 01:10:19+00:00
State: open

I'd like to see a closure type that binds `this`, i.e.

f = @(a,b) -> @foo

becomes

_self = this;
f = function(a,b) { (function() { this.foo }).call( _self ); }

because I constantly get bitten by the issue that closures are not bound by default. When applied in context of a property, as in

x = {
y : @(a,b) -> ...
}

Alternatively, it could be some other syntax; but it would be great to have a light-weight escape from JavaScript's weird binding rule.

It should be bound to the nearest enclosing lexical `this`, in this context what `this` would have resolved to right before `x = ...`