Yes, in such simple case you save only few keystrokes.
Imagine more complicated example:
function initServer(config) {
const {env, database, cache, logger} = config;
const {isDev} = env;
implementLogger(global, logger, isDev);
return Promise.all([databaseProvider(database), cacheProvider(cache),
envManager(env)]).then(([database, cache, env])=>({database, cache}));
}
It can be replaced by simpler:
function initServer({env: {isDev, *: env}, database, cache, logger, *:
config}) {
implementLogger(global, logger, isDev);
globalLogger.log(config);
return Promise.all([databaseProvider(database), cacheProvider(cache,
isDev), envManager(env)]).then(([database, cache, env])=>({database, cache,
env}));
}
When destructuring nested objects you can potentially save one line per
nest.
On Thu, May 19, 2016 at 9:47 PM, Isiah Meadows <[email protected]>
wrote:
> How is it any different than this, to borrow your first example:
>
> ```js
> function foo(baz) {
> const {bar} = baz
> // do things
> }
> ```
>
> On Thu, May 19, 2016, 11:59 Michał Wadas <[email protected]> wrote:
>
>> Idea:
>>
>> function foo({bar, *: baz}) {
>>
>> }
>>
>> would be equivalent to:
>>
>> function foo(baz) {
>> const bar = baz.bar;
>> }
>>
>> Rationales:
>> - little better IDE support (argument name reveals intention)
>> - allows to write more concise code when handling case of getting common
>> values and handling whole object optionally
>> - improve pattern "use few properties of options object then pass it
>> deeper"
>> - allows more expressive module import
>> - allows to more concise code when destructuring expression result
>>
>> import {*: rand, generateRandomInt} from 'fancy-random-module';
>> import {*: moment, isMoment} from 'moment';
>>
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss