source: node_modules/es-toolkit/dist/compat/function/bindKey.d.ts@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
3 *
4 * This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
5 *
6 * The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
7 *
8 * @template T - The type of the object to bind.
9 * @template K - The type of the key to bind.
10 * @param {T} object - The object to invoke the method on.
11 * @param {K} key - The key of the method.
12 * @param {...any} partialArgs - The arguments to be partially applied.
13 * @returns {T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never} - Returns the new bound function.
14 *
15 * @example
16 * const object = {
17 * user: 'fred',
18 * greet: function (greeting, punctuation) {
19 * return greeting + ' ' + this.user + punctuation;
20 * },
21 * };
22 *
23 * let bound = bindKey(object, 'greet', 'hi');
24 * bound('!');
25 * // => 'hi fred!'
26 *
27 * object.greet = function (greeting, punctuation) {
28 * return greeting + 'ya ' + this.user + punctuation;
29 * };
30 *
31 * bound('!');
32 * // => 'hiya fred!'
33 *
34 * // Bound with placeholders.
35 * bound = bindKey(object, 'greet', bindKey.placeholder, '!');
36 * bound('hi');
37 * // => 'hiya fred!'
38 */
39declare function bindKey(object: object, key: string, ...partialArgs: any[]): (...args: any[]) => any;
40declare namespace bindKey {
41 var placeholder: typeof bindKeyPlaceholder;
42}
43declare const bindKeyPlaceholder: unique symbol;
44
45export { bindKey };
Note: See TracBrowser for help on using the repository browser.