Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>var args = Array.prototype.slice.call(arguments).splice(1); </code></pre> <p>First takes a copy of <code>arguments</code>(*), then removes all but the first item from it (in a non-standard way), and assigns those items being removed to <code>args</code>.</p> <p>The extra array being produced, then altered and thrown away is quite redundant. It would be better to say — as the version in the answer you linked to indeed does:</p> <pre><code>var args = Array.prototype.slice.call(arguments, 1); </code></pre> <p>Partial function application is also a feature of the <code>function.bind</code> method, being standardised by ECMAScript Fifth Edition. Until browsers have implemented it, you can pick up an a fallback JS-native version from the bottom of <a href="https://stackoverflow.com/questions/1558065/access-event-object-in-event-handler/1558289#1558289">this answer</a>.</p> <p>*: <code>array.slice()</code> is the normal idiom for copying an array, and <code>array.slice(1)</code> for taking the tail. It has it be called explicitly through the <code>Array.prototype</code> because <code>arguments</code> is not an Array, even though it looks just like one, so doesn't have the normal array methods. This is another of JavaScript's weird mistakes.</p> <p>You quite often see people using the <code>Array.prototype</code> methods on objects that aren't Arrays; the ECMAScript Third Edition standard goes out of its way to say this is OK to do for the <code>arguments</code> array-like, but <strong>not</strong> that you may also do it on other array-likes that may be host objects, such as NodeList or HTMLCollection. Although you might get away with calling <code>Array.prototype</code> methods on a non-Array in many browsers today, the only place it is actually safe to do so is on <code>arguments</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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