1 var toInteger = require('./toInteger');
3 /** Error message constants. */
4 var FUNC_ERROR_TEXT = 'Expected a function';
7 * The opposite of `_.before`; this method creates a function that invokes
8 * `func` once it's called `n` or more times.
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.
19 * var saves = ['profile', 'settings'];
21 * var done = _.after(saves.length, function() {
22 * console.log('done saving!');
25 * _.forEach(saves, function(type) {
26 * asyncSave({ 'type': type, 'complete': done });
28 * // => Logs 'done saving!' after the two async saves have completed.
30 function after(n, func) {
31 if (typeof func != 'function') {
32 throw new TypeError(FUNC_ERROR_TEXT);
37 return func.apply(this, arguments);
42 module.exports = after;