source: trip-planner-front/node_modules/lodash/after.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1var toInteger = require('./toInteger');
2
3/** Error message constants. */
4var FUNC_ERROR_TEXT = 'Expected a function';
5
6/**
7 * The opposite of `_.before`; this method creates a function that invokes
8 * `func` once it's called `n` or more times.
9 *
10 * @static
11 * @memberOf _
12 * @since 0.1.0
13 * @category Function
14 * @param {number} n The number of calls before `func` is invoked.
15 * @param {Function} func The function to restrict.
16 * @returns {Function} Returns the new restricted function.
17 * @example
18 *
19 * var saves = ['profile', 'settings'];
20 *
21 * var done = _.after(saves.length, function() {
22 * console.log('done saving!');
23 * });
24 *
25 * _.forEach(saves, function(type) {
26 * asyncSave({ 'type': type, 'complete': done });
27 * });
28 * // => Logs 'done saving!' after the two async saves have completed.
29 */
30function after(n, func) {
31 if (typeof func != 'function') {
32 throw new TypeError(FUNC_ERROR_TEXT);
33 }
34 n = toInteger(n);
35 return function() {
36 if (--n < 1) {
37 return func.apply(this, arguments);
38 }
39 };
40}
41
42module.exports = after;
Note: See TracBrowser for help on using the repository browser.