D
D
Daniel Newman2016-06-26 13:28:51
JavaScript
Daniel Newman, 2016-06-26 13:28:51

Pros and cons of passing parameters by an object?

Faced with the need to pass the function 5+ string parameters and an object. I thought about it and began to transfer everything as a single object, from which I pull out the values ​​\u200b\u200band necessary in the function and object data. vs.
function (a,b,c,d,e,Object) {...};

function ({
 a: a,
 b: b,
 ......
 obj: Object[]
}) {...};

Now I arrive with a heady feeling that if there are more than three parameters, we leave for the object.
What explicit and implicit disadvantages and advantages do you know about passing parameters by an object?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2016-06-26
@danielnewman

There are no minuses, everything you thought was right, usually with four parameters or more, they already use an object to pass parameters.

S
semki096, 2016-06-26
@semki096

Quote from Mat Zanderstra. .. assigning properties to objects is considered bad form in OOP and is almost never used.

A
Alexey, 2016-06-26
@alexeyproject

Absolutely fine, use es2015(16)

let a = 22;
let b = 33;
let d = 44;

function fun({a, b, c}) {
//...
}

fun({a, b, c: d});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question