Function partialRight

  • Creates a function that invokes func with partials prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the "length" property of partially applied functions.

    Type Parameters

    • F extends ((...args) => any)

    Parameters

    • func: F

      The function to partially apply arguments to.

    • Rest ...partials: any[]

      The arguments to be partially applied.

      Rest

    Returns ((...args) => ReturnType<F>)

    Returns the new partially applied function.

      • (...args): ReturnType<F>
      • Parameters

        • Rest ...args: any[]
          Rest

        Returns ReturnType<F>

    Since

    5.5.0

    Example

    function greet(greeting, name) {
    return greeting + ' ' + name;
    }

    var greetFred = partialRight(greet, 'fred');
    greetFred('hi');
    // => 'hi fred'

    // Partially applied with placeholders.
    var sayHelloTo = partialRight(greet, 'hello', _);
    sayHelloTo('fred');
    // => 'hello fred'