Design & Download
Your JS Library
in Seconds!!!

Snippet: Spreading Array Values To A Function

Written by Christopher West (cwest) on December 09, 2015.
The spread(...) function is used to create a wrapper function which when called, calls the original function, spreading the values of the array passed in as individual arguments.
function spread(fn) {
  return function(args) {
    return fn.apply(this, args);
  };
}

spread(...) API Documentation

Description

Creates a wrapper function which when called, calls the original function, spreading the values of the array passed in as individual arguments.

Parameters

  1. fn {Function}:
    The function to be wrapped. Whatever this function returns the wrapper function will return.

Returns

Returns a wrapper function which when called will take only one array parameter whose values will be passed to fn() as individual arguments.