cap()

Puts a cap (limit) on the amount of arguments that a function can receive.

This function is valid in v2.1.0 to v2.24.3. This function has been downloaded 61 times.

Parameters

{Function|string} fn
The function that will be called by the capped function. If a string it be interpreted as the function within the YourJS object's context with that name.
{number=} opt_maxArity Optional, Default:fn.length
The max number of arguments that will be accepted by the returned capped function.
{Array=} opt_staticArgs Optional, Default:[]
Arguments that will always be passed to fn.
{number=} opt_indexInArgs Optional, Default:opt_staticArgs.length
Position within opt_staticArgs to place the limited additional arguments if any are passed to the capped function. Negative position will be counted from the end of opt_staticArgs.

Returns

{Function}
Returns a function that will call fn with the passed in arguments when invoked, but it will limit the argument count to the value opt_maxArity.

Required Function

This function directly requires the following function which is included automatically:

  • slice()
    Slice does not modify the original array, but instead returns a shallow copy of elements from the original array.