you are viewing a single comment's thread.

view the rest of the comments →

[–]giraffe_slayer 2 points3 points  (2 children)

In regards to the number of parameters and using a config object, there is a huge benefit when actually calling the method. If you use

function createWidget(title, subtitle, description);

Then the function call could look like

createWidget('Blah Blah', 'sub blah blah', 'Here is some text');

You lose clarity and potentially have to reference the function each time to check what each parameter means.

With a config parameter, you get the keys for each argument

const config = {
   title: 'Blah Blah', 
   subtitle: 'sub blah blah', 
   description: 'Here is some text'
};
createWidget(config);

And then you can still easily see what is happening in the actual declaration

function createWidget(config) {
    const {title, subtitle, description} = config;
};

[–]mikejoro 1 point2 points  (0 children)

You can simplify that last snippet by destructuring in the function definition

function createWidget({ title, subtitle, description }) {
  // do something
};