Function bind

  • Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

    The bind.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: Unlike native Function#bind, this method doesn't set the length property of bound functions.

    Type Parameters

    • F extends ((...args: any[]) => any)

      The type of the function to bind.

    Parameters

    • func: F

      The function to bind.

    • OptionalthisObj: unknown

      The this binding of func.

    • Rest...partialArgs: any[]

      The arguments to be partially applied.

    Returns F

    • Returns the new bound function.
    function greet(greeting, punctuation) {
    return greeting + ' ' + this.user + punctuation;
    }
    const object = { user: 'fred' };
    let bound = bind(greet, object, 'hi');
    bound('!');
    // => 'hi fred!'

    bound = bind(greet, object, bind.placeholder, '!');
    bound('hi');
    // => 'hi fred!'

Properties

Properties

placeholder: typeof bindPlaceholder