Monday, March 13, 2017

ES6 - What do function parameter lists inside of curly braces do in es6?


const func = ({ param1, param2 }) => {
    //do stuff
}

It is destructuring, but contained within the parameters. The equivalent without the destructuring would be:

const func = o => {
    var param1 = o.param1;
    var param2 = o.param2;
    //do stuff
}

It is basically shorthand for {param1: param1, param2: param2}


No comments:

Post a Comment

Followers

Blog Archive