|
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.2 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
|
|---|
| 3 | *
|
|---|
| 4 | * The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
|
|---|
| 5 | *
|
|---|
| 6 | * Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
|
|---|
| 7 | *
|
|---|
| 8 | * @param {(...args: any[]) => any} func - The function to bind.
|
|---|
| 9 | * @param {any} thisObj - The `this` binding of `func`.
|
|---|
| 10 | * @param {...any} partialArgs - The arguments to be partially applied.
|
|---|
| 11 | * @returns {(...args: any[]) => any} - Returns the new bound function.
|
|---|
| 12 | *
|
|---|
| 13 | * @example
|
|---|
| 14 | * function greet(greeting, punctuation) {
|
|---|
| 15 | * return greeting + ' ' + this.user + punctuation;
|
|---|
| 16 | * }
|
|---|
| 17 | * const object = { user: 'fred' };
|
|---|
| 18 | * let bound = bind(greet, object, 'hi');
|
|---|
| 19 | * bound('!');
|
|---|
| 20 | * // => 'hi fred!'
|
|---|
| 21 | *
|
|---|
| 22 | * bound = bind(greet, object, bind.placeholder, '!');
|
|---|
| 23 | * bound('hi');
|
|---|
| 24 | * // => 'hi fred!'
|
|---|
| 25 | */
|
|---|
| 26 | declare function bind(func: (...args: any[]) => any, thisObj: any, ...partialArgs: any[]): (...args: any[]) => any;
|
|---|
| 27 | declare namespace bind {
|
|---|
| 28 | var placeholder: typeof bindPlaceholder;
|
|---|
| 29 | }
|
|---|
| 30 | declare const bindPlaceholder: unique symbol;
|
|---|
| 31 |
|
|---|
| 32 | export { bind };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.