Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/nary-function/docs/types/index.d"

Index

Functions

Functions

Export assignment naryFunction

  • naryFunction(fcn: Function, arity: number, thisArg?: any): Function
  • Returns a function that applies a specified number of arguments to a provided function.

    Notes

    • The returned function always invokes the wrapped function with a specified number of arguments, even when the returned function is provided fewer arguments. The value for the missing arguments is equal to undefined.

    Parameters

    • fcn: Function

      input function

    • arity: number

      number of arguments to apply

    • Optional thisArg: any

      function context

    Returns Function

    function wrapper

    Example

    function foo() {
        var s;
        var i;
    
        s = 0;
        for ( i = 0; i < arguments.length; i++ ) {
            s += arguments[ i ];
        }
        return s;
    }
    
    var bar = naryFunction( foo, 2 );
    
    var out = bar( 1, 2, 3, 4, 5, 6 );
    // returns 3