This question already has an answer here:
- Named parameters in javascript 7 answers
Calling a Javascript function with something like
someFunction(1, true, 'foo');
is not very clear without familiarity with the function.
I have seen and used the style where comments are inserted to name the arguments:
someFunction(/*itemsToAdd*/1, /*displayLabel*/ true, /*labelText*/ 'foo');
But when it gets beyond 3 or more parameters, it seems better to pass arguments in a JSON object which makes it order-independent, and allows default values to be provided in the called function
someFunction({'itemsToAdd':1, 'labelText':'foo', 'displayLabel':true});
My question is; what is the general practice in the industry, and are there overriding reasons for not using any of these methods. Lint for example does not like the second method.