Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The term "splat operator" comes from Ruby, where the <code>*</code> character (sometimes called the "splat"—see <a href="http://www.catb.org/jargon/html/S/splat.html" rel="noreferrer">the Jargon File entry</a>) is used to indicate that an entry in an argument list should "soak up" a list of arguments.</p> <p>CoffeeScript adopted Ruby-style splats very early on (see <a href="https://github.com/jashkenas/coffee-script/issues/16" rel="noreferrer">issue 16</a>), but at Douglas Crockford's suggestion, the syntax was changed from <code>*x</code> to <code>x...</code> a couple of weeks later (see <a href="https://github.com/jashkenas/coffee-script/issues/45" rel="noreferrer">issue 45</a>). Nevertheless, CoffeeScripters still refer to the syntax as the "splat" or "splat operator."</p> <p>As to what they actually do, splats slice the <code>arguments</code> object in such a way that the splatted argument becomes an array of all "extra" arguments. The most trivial example is</p> <pre><code>(args...) -&gt; </code></pre> <p>In this case, <code>args</code> will simply be an array copy of <code>arguments</code>. Splatted arguments can come either before, after, or between standard arguments:</p> <pre><code>(first, rest...) -&gt; (rest..., last) -&gt; (first, rest..., last) -&gt; </code></pre> <p>In the first two cases, if the function receives 0-1 arguments, <code>rest</code> will be an empty array. In the last case, the function needs to receive more than 2 arguments for <code>rest</code> to be non-empty.</p> <p>Since JavaScript doesn't allow multiple signatures for functions with the same name (the way C and Java do), splats are a huge time-saver for dealing with varying numbers of arguments.</p>
    singulars
    1. This table or related slice is empty.
    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. 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