Sha256: 73d5b51a697642c4a8a855d06d337473ad15be8f2039287587ccdf760628531d

Contents?: true

Size: 1.69 KB

Versions: 270

Compression:

Stored size: 1.69 KB

Contents

var apply = require('./_apply'),
    arrayPush = require('./_arrayPush'),
    baseRest = require('./_baseRest'),
    castSlice = require('./_castSlice'),
    toInteger = require('./toInteger');

/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;

/**
 * Creates a function that invokes `func` with the `this` binding of the
 * create function and an array of arguments much like
 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
 *
 * **Note:** This method is based on the
 * [spread operator](https://mdn.io/spread_operator).
 *
 * @static
 * @memberOf _
 * @since 3.2.0
 * @category Function
 * @param {Function} func The function to spread arguments over.
 * @param {number} [start=0] The start position of the spread.
 * @returns {Function} Returns the new function.
 * @example
 *
 * var say = _.spread(function(who, what) {
 *   return who + ' says ' + what;
 * });
 *
 * say(['fred', 'hello']);
 * // => 'fred says hello'
 *
 * var numbers = Promise.all([
 *   Promise.resolve(40),
 *   Promise.resolve(36)
 * ]);
 *
 * numbers.then(_.spread(function(x, y) {
 *   return x + y;
 * }));
 * // => a Promise of 76
 */
function spread(func, start) {
  if (typeof func != 'function') {
    throw new TypeError(FUNC_ERROR_TEXT);
  }
  start = start == null ? 0 : nativeMax(toInteger(start), 0);
  return baseRest(function(args) {
    var array = args[start],
        otherArgs = castSlice(args, 0, start);

    if (array) {
      arrayPush(otherArgs, array);
    }
    return apply(func, this, otherArgs);
  });
}

module.exports = spread;

Version data entries

270 entries across 269 versions & 28 rubygems

Version Path
immosquare-cleaner-0.1.27 node_modules/lodash/spread.js
immosquare-cleaner-0.1.26 node_modules/lodash/spread.js
immosquare-cleaner-0.1.25 node_modules/lodash/spread.js
immosquare-cleaner-0.1.24 node_modules/lodash/spread.js
immosquare-cleaner-0.1.23 node_modules/lodash/spread.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/lodash/spread.js
reed_sdk-1.0.1 node_modules/lodash/spread.js
reed_sdk-1.0.0 node_modules/lodash/spread.js
boring_generators-0.12.0 tmp/templates/app_template/node_modules/lodash/spread.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/lodash/spread.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/lodash/spread.js
disco_app-0.18.0 test/dummy/node_modules/lodash/spread.js