Named `this` and `this` destructuring

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Thu Jun 18 05:59:51 UTC 2015


On Wed, Jun 17, 2015 at 11:38 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>
wrote:

>
> On Jun 17, 2015, at 10:01 AM, Jussi Kalliokoski wrote:
> ...
> >
> > More examples of the power of the bind syntax can be found in the links,
> but the bind syntax combined with my proposal would for example allow this:
> >
> > ```JS
> > function add (&a, b) { return a + b; }
> >
> > 2::add(3) // 5
> > ```
> >
> and why that better than:
> ```js
> function add(a,b) {return a+b}
>
> add(2,3);
> ```
>

Poor example, sorry.

Because of chaining in a way that preservers the natural read order of JS
and fitting in well with the builtins:

```JS

flatten(
    items // <- data here
        .filter(isOk)
        .map(toOtherType)
).join(" ");

```

vs.

```JS

items // <- data here
    .filter(isOk)
    .map(toOtherType)
    ::flatten()
    .join(" ");

```


As for fitting in (composing) well with the builtins, for example Trine
allows you to do this:

```JS
[["a", "b", "c"], ["e", "f", "g"]]::map([].slice); // yields copies of the
arrays
["foo", "bar"]::map("".repeat::partial(3)) // yields "foofoofoo",
"barbarbar"
```

because all the functions take data in the `this` slot, as most of the
builtins and framework methods do too.


>
> Every new feature increases the conceptual complexity of a language and to
> justify that it needs to provide a big pay back.


I wholeheartedly agree on this, which is why I stated that it might be too
early for my proposal.


> This doesn't seem to have much of a pay back.


Have no comments to that for my proposal. As for Kevin's proposal, I
disagree; the payback seems great in that one.


> Adding the & and :: doesn't eliminate the need for JS programmer to learn
> about `this` in functions for the various already existing ways to call a
> function with an explicit `this` value.  It just add more new syntax that
> needs to be learned and remembered are move feature interactions that have
> to be understood.
>

Agreed, however "not having to learn `this`" isn't the goal of either of
the proposals mentioned in this thread.


>
> JS doesn't need more syntax and semantics piled on to `this`.


Arguably JS hasn't "needed" anything since it became turing complete. That
doesn't mean that adding some of the things added since was a bad idea.
It's always a tradeoff, but that's nothing specific to this proposal.


> Ideally some would be taken away.  However, the latter is not possible.
>

Agree on this too. (As a tangent I'd be curious to know what you'd take
away, were it possible?)


>
> Allen
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150618/a0e9cae8/attachment-0001.html>


More information about the es-discuss mailing list