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

Brendan Eich brendan at mozilla.org
Sun Apr 29 11:37:06 PDT 2012


Brendan Eich wrote:
> But the lexical part doesn't enter into the contract of the API taking 
> the function argument. It's between the API caller and the function 
> argument's implementation -- when the latter is a closure in the 
> former, lexical |this| often wins. 

What does enter into the contract of the API taking the function 
argument is whether |this| is dynamically bound and passed with the 
expectation that the funarg not use some other |this|. But even then, 
the funarg is free to ignore |this|.

Between lexical-this and no-this, Kevin's analysis shows 80-90% (high 
end helped by method definition shorthand) coverage.

Thinking about arrows as a new thing to teach is fine, but we should not 
teach myths. |this| binding in JS today requires careful thought in all 
the usual scenarios: constructor, method, callback, global or local 
function. You can see why some advocate no-this uber alles!

But lexical-this is (if memory serves) around 40-50% gross of the 80-90% 
Kevin studied. That's big and we know people get that wrong.

If there's a strong use-case for -> as function shorthand, we should 
consider adding -> too. But the use-cases don't look strong enough yet, 
at least not to me (and I'm sympathetic!) to go back to TC39 asking for 
-> on top of =>.

/be


More information about the es-discuss mailing list