Optional argument first in JavaScript
<p>For the user's ease, I have a function that receives an optional argument first, before the required argument. For example:</p>

<pre><code>ns.myFunction('optional arg', function(){
    //the required callback
});
</code></pre>

<p>I'm doing this rather than doing the following since the callback body could be long, and the user might forget to override the defaults to the optional arguments:</p>

<pre><code>ns.myFunction(function(){
    //the required callback
}, 'optional arg');
</code></pre>

<p>Currently I'm doing this to check:</p>

<pre><code>function myFunction(first, second) {

    //if second is undefined and first is a function
    if (typeof second === 'undefined' &amp;&amp; typeof first === 'function') { 
        second = first;
    }
}
</code></pre>

<p>Questions</p>

<ul>
<li>Is this the right way? </li>
<li>How would I do it so that it scales, especially if there were N optional arguments that are before the required argument?</li>
</ul>
