Sha256: ca045b1ae9e085d50cb03af9568f0523470138cef8b83246182f3fb81fa9f095

Contents?: true

Size: 1.04 KB

Versions: 273

Compression:

Stored size: 1.04 KB

Contents

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

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

/**
 * The opposite of `_.before`; this method creates a function that invokes
 * `func` once it's called `n` or more times.
 *
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Function
 * @param {number} n The number of calls before `func` is invoked.
 * @param {Function} func The function to restrict.
 * @returns {Function} Returns the new restricted function.
 * @example
 *
 * var saves = ['profile', 'settings'];
 *
 * var done = _.after(saves.length, function() {
 *   console.log('done saving!');
 * });
 *
 * _.forEach(saves, function(type) {
 *   asyncSave({ 'type': type, 'complete': done });
 * });
 * // => Logs 'done saving!' after the two async saves have completed.
 */
function after(n, func) {
  if (typeof func != 'function') {
    throw new TypeError(FUNC_ERROR_TEXT);
  }
  n = toInteger(n);
  return function() {
    if (--n < 1) {
      return func.apply(this, arguments);
    }
  };
}

module.exports = after;

Version data entries

273 entries across 271 versions & 29 rubygems

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