On Tue, Apr 24, 2018 at 4:24 PM, Michael Luder-Rosefield
<rosyatran...@gmail.com> wrote:
> I've found myself using that pattern, actually. Say you have multiple
> variables and want to pass one of them on to a function, which wants to know
> the value (of course) of that variable but also some kind of name to know
> which one was passed on.
>
> The easiest way to do this in one pass at the stage you pass it on is for
> the variable name to match the one needed later, and send it to the function
> as the object `{ whateverName }`.

On those rare occasions, the way I'd use would be `["whateverName",
whateverName]` (granted it's more verbose at the call site). That's
what `Object.entries` and `Map.prototype.entries` do, for instance,
and it's friendly to destructuring:

```js
function example([name, value]) {
    console.log(`${name} = ${value}`);
}
example(["answer", 42]);
```

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to