Rework the doc example for _.after.

This commit is contained in:
John-David Dalton
2013-08-29 07:43:05 -07:00
parent 816381a6a8
commit 6c1a9dc14b

View File

@@ -5103,8 +5103,8 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/** /**
* Creates a function this is restricted to executing `func` with the `this` * Creates a function that executes `func`, with the `this` binding and
* binding and arguments of the created function, only after it is called `n` times. * arguments of the created function, only after being called `n` times.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -5115,11 +5115,16 @@
* @returns {Function} Returns the new restricted function. * @returns {Function} Returns the new restricted function.
* @example * @example
* *
* var renderNotes = _.after(notes.length, render); * var saves = ['profile', 'settings'];
* _.forEach(notes, function(note) { *
* note.asyncSave({ 'success': renderNotes }); * var done = _.after(saves.length, function() {
* console.log('Done saving!');
* }); * });
* // `renderNotes` is run once, after all notes have saved *
* _.forEach(saves, function(type) {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => logs 'Done saving!', after all saves have completed
*/ */
function after(n, func) { function after(n, func) {
if (!isFunction(func)) { if (!isFunction(func)) {