Skip to content

Instantly share code, notes, and snippets.

@PaulMougel
Created December 23, 2013 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulMougel/8103140 to your computer and use it in GitHub Desktop.
Save PaulMougel/8103140 to your computer and use it in GitHub Desktop.
~/tmp ❯❯❯ node index.js
null
[ {}, {}, {} ]
var async = require('async');
var FabricCommand = function() {};
FabricCommand.prototype.do = function (undoArray, callback) {
// Check the number of arguments
// (the first function of the waterfall receives only a callback)
if (Array.prototype.slice.apply(arguments).length === 1) {
callback = undoArray;
undoArray = undefined;
}
var self = this;
if (undoArray === undefined) {
undoArray = [];
}
undoArray.push(self);
callback(null, undoArray);
};
var doCommands = [];
var f1 = new FabricCommand();
var f2 = new FabricCommand();
var f3 = new FabricCommand();
doCommands.push(f1.do.bind(f1));
doCommands.push(f2.do.bind(f2));
doCommands.push(f3.do.bind(f3));
async.waterfall(
doCommands,
function (err, undoCommands) {
console.log(err);
console.log(undoCommands);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment