1 /** Used as the `TypeError` message for "Functions" methods. */
2 var FUNC_ERROR_TEXT = 'Expected a function';
4 /* Native method references for those with the same name as other `lodash` methods. */
5 var nativeIsFinite = global.isFinite;
8 * The opposite of `_.before`; this method creates a function that invokes
9 * `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 if (typeof n == 'function') {
37 throw new TypeError(FUNC_ERROR_TEXT);
40 n = nativeIsFinite(n = +n) ? n : 0;
43 return func.apply(this, arguments);
48 module.exports = after;