Sha256: 3684db1e49dd7760c220bcf1c3d27f1fb052773b641f4e7fa09ec5e1a3e850d9

Contents?: true

Size: 1.13 KB

Versions: 153

Compression:

Stored size: 1.13 KB

Contents

/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';

/**
 * Creates a function that invokes `func`, with the `this` binding and arguments
 * of the created function, while it's called less than `n` times. Subsequent
 * calls to the created function return the result of the last `func` invocation.
 *
 * @static
 * @memberOf _
 * @category Function
 * @param {number} n The number of calls at which `func` is no longer invoked.
 * @param {Function} func The function to restrict.
 * @returns {Function} Returns the new restricted function.
 * @example
 *
 * jQuery('#add').on('click', _.before(5, addContactToList));
 * // => allows adding up to 4 contacts to the list
 */
function before(n, func) {
  var result;
  if (typeof func != 'function') {
    if (typeof n == 'function') {
      var temp = n;
      n = func;
      func = temp;
    } else {
      throw new TypeError(FUNC_ERROR_TEXT);
    }
  }
  return function() {
    if (--n > 0) {
      result = func.apply(this, arguments);
    }
    if (n <= 1) {
      func = undefined;
    }
    return result;
  };
}

module.exports = before;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/before.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/before.js