Bound instance-function vending (was RE: Arrow binding)

Axel Rauschmayer axel at rauschma.de
Sun Apr 29 03:24:52 PDT 2012


With “rules”, I don’t mean rules in the sense of the language spec, but rather rules for teaching the language to newcomers.

On Apr 29, 2012, at 10:28 , Brendan Eich wrote:

> Axel Rauschmayer wrote:
>> I am not saying that the transition from the old rules to the new rules will be entirely painless, but if the new rules are simple, that pain is worth it, IMHO.
> 
> There are no new rules. Some functions ignore |this| or bind it rather than using it. These differences in kind do not change due to arrows.
> 
>>  Library code might need to go to extra lengths to help normal developers with the transition (error messages, different behavior, tool functions, etc.) and – to be explicit – might need a predicate such as `isArrowFunction` (which should only ever be used under the hood and thus would not increase confusion for library*users*).
> 
> There's no point in such a misnamed predicate. Today we have functions that ignore or bind |this|, as well as those that use |this| passed by the caller. Code requires and assumes one kind or another and does not test (and most programmers wouldn't cover all cases, and shouldn't have to).
> 
> Part of an API, an essential part of the contract, is any function parameter's |this| binding. Arrows make it easier to use callbacks wanting lexical |this| or not using |this| at all. This covers a large cohort. Code invoking the arrow is not going to test well or at all and do something helpful, or unhelpful such as throwing an exception.
> 
> /be
> 

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120429/bc2467fc/attachment.html>


More information about the es-discuss mailing list