1. Home
  2. Javascript
  3. Destructuring function parameters

Use object destructuring to pass arguments in the function parameters.

#javascript#destructuring#es6
class Shape {
    createShape(options = {}) {
        const { x = 0, y = 0, w = 100, h = 100, c = '#FFF'} = options;
        console.log(x,y,w,h,c);
    }
}

const shape = new Shape();
shape.createShape({});
copy
Full Javascript cheatsheet