On Wed, Mar 28, 2012 at 3:57 PM, Kevin Smith <[email protected]> wrote:

> Russell, I looked at the other thread more carefully and now understand
> what you're saying.  Can't we use a bound |this| function for all these
> cases?
>
>     needsCallback(x => foo.bar(x));
>     needsCallback(x => this.bar(x));
>
>     // Suppose for a moment that -> also binds |this|
>     needsCallback((x, y) -> {
>   if (x) this.doX(x);
>  else this.doY(y);
>   });
>
> It seems that with bound |this| functions, the need to explicitly bind
> |this| tends to fall away.
>

Yeah, I mean look - it may be that having short function with bound this
and implicit return can get the job done. Of course, it seems so easy with
just one argument called x. Its a little different if it looks more like:

    needsCallback((event,data) => foo.bar(event,data));
    needsCallback((element,index,array) => this.bar(element,index,array));

Would you shorten or put in dummy arg names?

    needsCallback((e,d) => foo.bar(e,d));
    needsCallback((a,b,c) => this.bar(a,b,c));

What if you didn't want to worry about the arguments? I mean, there's no
reason you should have to make this know the contract between the function
call and the callback params. I guess we could use rest params.

    needsCallback((args...) => this.bar(args...));

But obviously that starts to seem like a code smell, especially if you have
multiple:

    doSomething({
      success: (args...) => this.success(args...),
      error: (args...) => this.error(args...)
    });

In this case it doesn't really beat bind, and maybe it doesn't have to, but
in relation to the short function syntax thread, it's possible that this
makes sense as a way of composing different parts.

- Russ


>
> kevin
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to