よくわからないエラーが出ます。関数の配列で async.waterfall を呼び出しています。関数は、わかりやすくするために「短縮」されています。
FabricCommand.prototype.do = function (callback, undoArray) {
var self = this;
if (undoArray === undefined) {
undoArray = [];
}
undoArray.push(self);
callback(null, undoArray);
};
以下に示すように配列を作成します。doCommands は配列であり、オブジェクトはそのように追加されます。
doCommands.push(fabricCommand.do.bind(fabricCommand));
ウォーターフォールのセットアップ:
async.waterfall(
doCommands,
function(err, undoCommands){
if (err) {
// do something ...
}
else {
console.log('we succeeded with all the do commands... and there are '
+ undoCommands.length
+ ' in the undoCommands but we will disregard it...');
}
}
);
このコードを実行すると、最初に FabricCommand.do 関数を使用して、undoCommands 配列を割り当て、それに 1 つ追加します。次回は、配列要素を追加しようとすると、次のエラーが表示されます。
undoArray.push(something);
^ TypeError: Object function (err) {
if (err) {
callback.apply(null, arguments);
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
async.setImmediate(function () {
iterator.apply(null, args);
});
}
} has no method 'push'
誰かが私が間違っていることを見ることができますか?