Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,28 @@ <h2 id="functions">Function (uh, ahem) Functions</h2>
_.each(everyoneElse, sendConsolations);
});

raceResults("Dopey", "Grumpy", "Happy", "Sneezy", "Bashful", "Sleepy", "Doc");
</pre>
<p id="restArguments-startIndex">
The <b>startIndex</b> is mainly useful if the number of arguments cannot be reliably determined from the <b>function</b> itself, for example because <b>function</b> was output by another function.
</p>
<pre>
// The inner function from before.
function consoleNonWinners(gold, silver, bronze, everyoneElse) {
_.each(everyoneElse, sendConsolations);
}

// This time, we transform it through another metafunction first.
// Snow White always wins gold!
var withSnowWhite = _.partial(consoleNonWinners, "Snow White");

// withSnowWhite.length is zero because _.partial does not remember the
// number of parameters for us. We fix this by passing an explicit
// startIndex.
var raceResults = _.restArguments(withSnowWhite, 2);

// Dopey degraded to silver, Grumpy degraded to bronze and Happy fell
// out of the prizes altogether. We will console him as well.
raceResults("Dopey", "Grumpy", "Happy", "Sneezy", "Bashful", "Sleepy", "Doc");
</pre>

Expand Down