Arrow functions as methods

Gordon Brander gbrander at mozilla.com
Wed Jul 11 10:46:15 PDT 2012


On Jul 11, 2012, at 10:41 AM, Irakli Gozalishvili wrote:
> If `object.foo` is an arrow function it has no way of knowing weather it was invoked as a function or a method. Neither it get's reference to an `object`. This makes composition between functional & OO styles components hard. 


On Wednesday, 2012-07-11 at 10:23 , Irakli Gozalishvili wrote:
> It is true that on could wrap arrow function into vintage one in order to reuse it as a method, but that is a poor mans workaround. As of motivation, all I really want is to have a synergy of different paradigms that are in the language.
> 
> What I really mean by that is, if one writes in a functional style:
> That should be reusable in OO code without any changes or wrappers:


I agree. In general, having compatible semantics allows you to manipulate code programmatically instead of writing wrapper code by hand. The more inter-compatible language concepts are, the less mechanical busy work you have to write.

Methods and functions are both "callable bundles of procedural logic", so having 2 incompatible semantics for them seems silly to me.

There is also precedent for this approach: Python, and I think Lua, do methods this way. It cleverly side-steps the need to have a different semantic for functions and methods.

Best,
-Gordon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120711/c3edc96d/attachment.html>


More information about the es-discuss mailing list