On Wed, May 30, 2012 at 10:32 AM, Allen Wirfs-Brock <[email protected]>wrote:
> > On May 29, 2012, at 10:05 PM, Rick Waldron wrote: > > > On Wednesday, May 30, 2012 at 12:00 AM, Russell Leggett wrote: > > > > On Tue, May 29, 2012 at 11:52 PM, John Tamplin <[email protected]> wrote: > > On Tue, May 29, 2012 at 11:50 PM, Yehuda Katz <[email protected]> wrote: > > I'm not sure if this makes sense, but something about breaking `call` and > `apply` doesn't sit right with me. > > > Why should an arrow function be treated any differently than an explicitly > bound function (ie, via bind)? > > > > Hah, you beat me too it, I was typing in almost the exact same thing. And > not just bind, either - even the kind of workarounds people would use > before bind like 'var self = this' sorts of things. If someone writes code > using the arrow, what they want is to use the lexically scoped this - they > want to use 'this' just like any other reference captured by the closure. > > Any use of call or apply has to be done carefully and requires knowledge > of how 'this' is used. It effectively becomes another parameter to the > function. In cases of bind or an arrow function, 'this' is removed as a > parameter and is purely another captured reference. There's no special call > function to let you override other closed over values. Why should arrow > function's behavior for 'this' be any different? > > There is also no reason to think of => as all or nothing, jQuery and it's > APIs can still use function expressions where dynamic |this| is expected. > If a user tries to pass => to any of these APIs, they will learn quickly > that they've done it wrong. > > > However, there might be some utility (at least for debugging) in having a > Function.prototype.isThisBound method. It would return true for arrow > functions and functions created via Function.prototype.bind > I agree that such a predicate would be useful, but the useful predicate should also give "true" for functions that don't mention "this". Thus, "isThisBound" may not be the right name. What it really means is 'Can this function sense the "this" binding with which it is called?" If we call it "canSenseThis", then clearly we should also reverse the truth value. -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

