1 var toInteger = require('./toInteger');
3 /** Used as the `TypeError` message for "Functions" methods. */
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.
13 * @param {number} n The number of calls before `func` is invoked.
14 * @param {Function} func The function to restrict.
15 * @returns {Function} Returns the new restricted function.
18 * var saves = ['profile', 'settings'];
20 * var done = _.after(saves.length, function() {
21 * console.log('done saving!');
24 * _.forEach(saves, function(type) {
25 * asyncSave({ 'type': type, 'complete': done });
27 * // => logs 'done saving!' after the two async saves have completed
29 function after(n, func) {
30 if (typeof func != 'function') {
31 throw new TypeError(FUNC_ERROR_TEXT);
36 return func.apply(this, arguments);
41 module.exports = after;