Sha256: 0cc79ed65583090e486d4840ba33088f80db5f81ffd00a55956cae909facda1e

Contents?: true

Size: 1.06 KB

Versions: 273

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

273 entries across 271 versions & 29 rubygems

Version Path
clapton-0.0.19 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/lodash/before.js
immosquare-cleaner-0.1.49 node_modules/lodash/before.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/lodash/before.js
immosquare-cleaner-0.1.48 node_modules/lodash/before.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.6 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.5 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.4 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.3 lib/clapton/javascripts/node_modules/lodash/before.js
clapton-0.0.2 lib/clapton/javascripts/node_modules/lodash/before.js