Destructuring assignment and $.extend without jquery
in front-end / Javascript on ES6 - Hits()
We are familiar with the jquery function, $.extrend. Now with Destructuring assignment, we can do it like this:
const foo = { fizzBuzz: true };
//later override previous one
const bar1 = { fizzBuzz:false,...foo};
const bar2 = { ...foo,fizzBuzz:false};
console.log(bar1.fizzBuzz); // "true"
console.log(bar2.fizzBuzz); // "false"
This feature is not a standard of ES6 yet(Initial definition), you can see the browser support at the same page.
Here is another example:
//Destructuring assignment
let a = 1;
let b = {a}; //{a} is not a valid json, but here it actually do a Destructuring assignment
console.log(b);
console.log({a});// destructuring directly
so, as we are familiar with code like:
function xxx(){
}
module.exports = {xxx};
Actually it is a Destructuring assignment.