Concise Method Binding

Jordan Harband ljharb at gmail.com
Tue Nov 10 02:19:21 UTC 2015


In your first example, the arrow function's "this" would be the "this" of
the context the "class" is defined in - it wouldn't be bound at all. Can
you point me to an example of where that example "bar" is a function bound
to the instance?

On Mon, Nov 9, 2015 at 5:45 PM, JD Isaacks <jd at jisaacks.com> wrote:

> Considering the proposals for both concise methods and the bind operator I
> think it would be a great addition to be able to use them together.
>
> I am already seeing a lot of this:
>
> class Foo {
>   bar = () => {
>     // bound
>   }
>   buz() {
>     // unbound
>   }
> }
>
>
> I think having the bind operator with a concise method makes things more
> uniform:
>
> class Foo {
>   ::bar() {
>     // bound
>   }
>   buz() {
>     // unbound
>   }
> }
>
>
> This would also allow for this to be using on object literals:
>
> let foo = {
>   ::bar() {
>     // bound
>   }
>   buz() {
>     // unbound
>   }
> }
>
>
> This would also make using recursion with concise functions feasible:
>
> let fibonacci = {
>   ::at(n) {
>     if (n < 2) {
>       return n;
>     }
>     return this.at(n-1) + this.at(n-2);
>   }
> }
> fibonacci.at(7); // 13
>
>
> I am looking for a champion for this feature. Anybody interested?
>
> Thanks,
> JD Isaacks
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151109/60d9c356/attachment.html>


More information about the es-discuss mailing list