diff --git a/index.html b/index.html index e2174607d..a0eb92b0d 100644 --- a/index.html +++ b/index.html @@ -1818,6 +1818,28 @@

Function (uh, ahem) Functions

_.each(everyoneElse, sendConsolations); }); +raceResults("Dopey", "Grumpy", "Happy", "Sneezy", "Bashful", "Sleepy", "Doc"); + +

+ The startIndex is mainly useful if the number of arguments cannot be reliably determined from the function itself, for example because function was output by another function. +

+
+// 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");