-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
In MoonScript, it's possible to get a reference to an object method that remains bound to its original object. This feature is called a "function stub" and works like this:
higherOrderFunction obj\method
-- compiles to
return higherOrderFunction((function()
local _base_0 = obj
local _fn_0 = _base_0.method
return function(...)
return _fn_0(_base_0, ...)
end
end)())Given the way JavaScript's objects work and that Function::bind isn't reliably available on all browsers, a similar functionality in CoffeeScript would be valuable.
We don't use \ to denote method calls in CoffeeScript, so simply copying MoonScript's notation for the concept wouldn't work so well; perhaps reusing the bound-function symbol => in the contexts we use . would, like so?
higherOrderFunction obj=>methodWould compile to:
higherOrderFunction(function () {
return obj.method.apply(obj, arguments);
});The above CoffeeScript is currently a syntax error, so adding this use for => shouldn't break backwards-compat with anything. I'm open to other operator suggestions, of course.
Reactions are currently unavailable