Using ES2016 (ES7) Can I replace the underline matching method?

The only thing I did not understand how to do this using the new ES syntax is to create an object that is a subset of the other, based on the declared included values.

Here is what I am trying to do:

//input let user = { id: 123, foo: 'foo', bar: 'bar', password: 'hunter2' }; //output let safeUser = { id: user.id, foo: user.foo, bar: user.bar } //NOT this (I don't want to declare excluded vals) let {password, ...safeUser} = user; 

If this is not possible, does anyone know if there is anything in the work? I looked at esdiscuss and babel, but nothing appeared.

+5
source share

Source: https://habr.com/ru/post/1237147/


All Articles