【发布时间】:2015-02-20 20:37:24
【问题描述】:
我正在使用when 承诺库来lift() 我的节点样式回调并承诺它们......
var nodefn = require('when/node');
var one = nodefn.lift(oneFn),
two = nodefn.lift(twoFn),
three = nodefn.lift(threeFn);
function oneFn(callback){
console.log('one');
callback(null);
}
function twoFn(callback){
console.log('two');
callback(null);
}
function threeFn(callback){
console.log('three');
callback(null);
}
我想调用链中的函数,像这样:
one().then(two).then(three).done();
但是调用第二个回调函数时却报错:
Uncaught TypeError: undefined is not a function
错误是指twoFn(callback) 中的callback 函数。
将这些函数链接在一起并一个接一个地执行的正确方法是什么?
【问题讨论】:
-
我有一段时间没有使用
when,也不知道when.lift,但我想你需要这样做:one().then(function() { return two();}).then(function() {return three();}).done();
标签: javascript promise browserify when-js