我收到一个我不明白的错误。我用一组函数调用 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 数组并向其中添加了一个,下一次通过我尝试添加数组元素的地方,出现以下错误:
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'
谁能看到我做错了什么?