Inner functions and outer 'this' (Re: That hash symbol)

Brendan Eich brendan at mozilla.com
Wed Mar 30 16:24:09 PDT 2011


See http://wiki.ecmascript.org/doku.php?id=strawman:soft_bind for the method-API proposal.

/be

On Mar 30, 2011, at 2:11 PM, David Herman wrote:

> If I've got this right, the idea of soft bind is that the function distinguishes whether it's called as a function or as a method; if called as a function, it uses the lexical binding of |this|, and if called as a method, it uses the dynamically pass-in binding of |this|.
> 
> Note that the .call and .apply methods don't allow you to make this distinction.
> 
> Dave
> 
> On Mar 30, 2011, at 1:14 PM, P T Withington wrote:
> 
>> On 2011-03-29, at 17:38, Brendan Eich wrote:
>> 
>> [...]
>>> We did not discuss allowing |this| to be bound otherwise, *except*
>>> 
>>> #foo(this = this| arg1, arg2) {...}
>> 
>> Am I right in understanding the above to be an idiom for trampolining the outer `this` binding into the closure?  (With the hazard that someone could override that binding.)  Or are you just giving an example, not endorsing a particular idiom?
>> 
>> [...]
>> 
>>> The other use-case, what Alex Russell calls soft-bind, also wants |this| not |^this|.
>> 
>> Is there an example of what 'soft-bind' means somewhere?
> 



More information about the es-discuss mailing list