From 540b0758b3261e04bde1abb67915530e6a887ec0 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Thu, 20 Feb 2025 18:03:06 +0100 Subject: [PATCH] Add documentation for the startIndex argument of restArguments Motivation: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71151#issuecomment-2641787764 --- index.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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");