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

Kam Kasravi kamkasravi at yahoo.com
Thu Mar 31 10:32:27 PDT 2011


How reasonable would it be to treat 'this' in a similar way that the prototype chain is referenced when resolving identifiers? I realize there would be ambiguity for like named identifiers but that problem exists now... In Allen's first example this.handleClick(this,e) would not be resolved with it's implicit binding to elem, so 'this' would be bound lexically and the code would just work. The second 'this' would of course default to the implicit binding.

On Mar 30, 2011, at 4:24 PM, Brendan Eich <brendan at mozilla.com> wrote:

> 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?
>> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list