arrows and a proposed softCall
Angus Croll
anguscroll at gmail.com
Mon Jun 4 09:28:42 PDT 2012
I actually agree. I included non-this methods only because reading through
this thread I got a feeling that there was some consensus that they be
treated differently. More than happy to not do that.
On Mon, Jun 4, 2012 at 8:16 AM, Andreas Rossberg <rossberg at google.com>wrote:
> On 3 June 2012 20:13, Angus Croll <anguscroll at gmail.com> wrote:
> > Not suggesting that arrow functions be special cased or that they ignore
> > |thisArg|. I'm suggesting for all relevant cases (=>, bind and no
> |this|) we
> > only throw an error on call/apply if the |thisArg| is non null.
>
> That would not only be a breaking change, as Brendan pointed out. More
> importantly, it would also not be something you truly want. Consider
> this piece of code:
>
> function C(x) { this.x = x }
> C.prototype.f = function() { return this.x }
> C.prototype.g = function() { return this.f() * 2 }
> C.prototype.h = function() { return 41 }
>
> let o = new C(21)
> foo(o, [o.f, o.g, o.h])
>
> where
>
> function foo(o, funs) {
> // ...
> for (let f of values(funs)) {
> result += f.call(o)
> }
> }
>
> According to your suggestion, foo would throw. But there is no actual
> reason why foo should care that h is a constant method. That's an
> implementation detail. Why should the caller have to jump through
> hoops to account for implementation details of the callee?
>
> I think there is a misconception here is that this-oblivious
> methods/functions are something _different_ from "normal"
> methods/functions. They aren't. They are just a _special case_ of
> normal methods/functions. Just like functions that ignore any other
> parameter. Consequently, you don't usually want to treat them
> differently. I claim that code that tries has a 98% likelihood of
> being broken -- or at least of smelling rather bad.
>
> /Andreas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120604/3c4f3d76/attachment.html>
More information about the es-discuss
mailing list