Sha256: 0cc79ed65583090e486d4840ba33088f80db5f81ffd00a55956cae909facda1e

Contents?: true

Size: 1.06 KB

Versions: 276

Compression:

Stored size: 1.06 KB

Contents

var toInteger = require('./toInteger');

/** Error message constants. */
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 _
 * @since 3.0.0
 * @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(element).on('click', _.before(5, addContactToList));
 * // => Allows adding up to 4 contacts to the list.
 */
function before(n, func) {
  var result;
  if (typeof func != 'function') {
    throw new TypeError(FUNC_ERROR_TEXT);
  }
  n = toInteger(n);
  return function() {
    if (--n > 0) {
      result = func.apply(this, arguments);
    }
    if (n <= 1) {
      func = undefined;
    }
    return result;
  };
}

module.exports = before;

Version data entries

276 entries across 274 versions & 30 rubygems

Version Path
appmap-0.68.2 ./node_modules/lodash/before.js
appmap-0.68.1 ./node_modules/lodash/before.js
disco_app-0.15.2 test/dummy/node_modules/lodash/before.js
appmap-0.68.0 ./node_modules/lodash/before.js
appmap-0.67.1 ./node_modules/lodash/before.js
trusty-cms-5.0.3 node_modules/lodash/before.js
trusty-cms-5.0.2 node_modules/lodash/before.js
appmap-0.67.0 ./node_modules/lodash/before.js
disco_app-0.18.4 test/dummy/node_modules/lodash/before.js
disco_app-0.18.1 test/dummy/node_modules/lodash/before.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/lodash/before.js
disco_app-0.14.0 test/dummy/node_modules/lodash/before.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/lodash/before.js
appmap-0.66.2 ./node_modules/lodash/before.js
trusty-cms-5.0.1 node_modules/lodash/before.js
trusty-cms-4.3.5 node_modules/lodash/before.js
trusty-cms-5.0.0 node_modules/lodash/before.js
appmap-0.66.1 ./node_modules/lodash/before.js
appmap-0.66.0 ./node_modules/lodash/before.js
appmap-0.65.1 ./node_modules/lodash/before.js