Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Indeed, that is a pro to the multi-parameter method.</p> <p>As people have mentioned here, the advantage to a js object (an array here isn't as nice IMO) is that the function signature becomes flexible. Not that javascript enforces this like other languages, but still it helps to be able to not have to change the function signature every time you want to change the parameters.</p> <p>Facebook, to use the example you brought, change their SDK's and other protocols every 10 minutes (I hated developing with Facebook's stuff, their documentation is appalling and they have a sadistic tendency to slip the carpet from under your feet by bringing out new versions of everything without backward-compatibility. Although this is not the place for this rant). So for them, this would be helpful.</p> <p>One distinction that I find useful in some scenarios:</p> <p>Often when a function performs a certain action, there are parameters that define on what <em>values</em> the function should perform its task. For instance <code>compare(3,4)</code> will perform the relevant arithmetic on the arguments <code>3</code> and <code>4</code>.</p> <p>Another group of parameters are those that define how the function should <em>behave</em>. For example <code>compare(3,4,'strict')</code>. Here, I'm not comparing <code>'strict'</code> to anything, rather that parameter tells the function that I want to perform a specific type of comparison.</p> <p>In this example it seems unlikely that much will change so the topic is mostly irrelevant, although on larger more complex functions this isn't the case. I often find that the most "stable" parameters are the <em>values</em>, around which the definition of the function is usually based. Whereas <em>behavioural</em> parameters change more often, and more often don't exist.</p> <p>In addition to making the method signature more "stable", it makes code more readable because on each function call you can usually see what the operands of the function will be, as opposed to a single object, which is more difficult to understand and debug.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload