Search code examples
javascriptoperatorsdestructuring

What is this es6 assignment operator?


If this operator declared:

const { assign, isEmpty, run } = Ember;

Then, instead of:

Ember.run(() => { ... });
Ember.assign(foo, {});

It can be written as:

run(() => { ... });
assign(foo, {});

Which is much nicer!

What is it and how does it work?

Note: I'll edit this question to make it clearer when I know...


Solution

  • It's called destructuring and yes, it's very nice. Very convenient for cleaning up your code.

    As explained by MDN:

    The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

    Full reference here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment