Skip to content
Merged
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
31 changes: 31 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,37 @@ <h2 id="functions">Function (uh, ahem) Functions</h2>
});

raceResults("Dopey", "Grumpy", "Happy", "Sneezy", "Bashful", "Sleepy", "Doc");
// Sorry Sneezy, better next time!
// Sorry Bashful, better next time!
// Sorry Sleepy, better next time!
// Sorry Doc, better next time!
</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");
// Sorry Happy, better next time!
// Sorry Sneezy, better next time!
// Sorry Bashful, better next time!
// Sorry Sleepy, better next time!
// Sorry Doc, better next time!
</pre>

<h2 id="objects">Object Functions</h2>
Expand Down
Loading