return =

Bob Myers rtm at gol.com
Mon Sep 3 18:19:55 UTC 2018


To continue the "stupid idea of the day" series, I have often felt the need
to indicate a return value other than as part of a `return` statement.

Perhaps this is my BASIC background--the dialect I used all those years ago
allowed an assignment to the function name to pre-specify a return value,
which would then be used whenever the function finally finished.

My initial suggestion is to use the `return =` syntax, which is a syntax
error right now so it should not conflict with anything.

Trivial examples:

```js
function double(a) {
  const b = return = [];
  for (elt of a) b.push(elt*2);
}
```

```js
function bar() {
  const val = someCalculation();
  report(return = val);
}
```

Not to belabor the point, but of course there is no new functionality here;
it's just a matter of conciseness. However, it could also perhaps be used
to allow the use of arrow functions when you want to do something without
returning its value but maintain the concise body form:

```js
const a = () => doThing(return = a);
```

Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180903/029c17dc/attachment.html>


More information about the es-discuss mailing list