我知道这非常愚蠢,但如何启动承诺链?我有,例如,
var p = new Promise(function(resolve,reject) {
setTimeout(function() {
return resolve("Hi from promise after timeout");
},1000);
});
如何运行它?它应该是那样的,
when(p)
.then(function(msg) {
console.log(msg);
})
.catch(function(error) {
console.error(error);
});
但when
未定义。
答案 0 :(得分:7)
你只需要这样做:
p.then(function(msg) {
console.log(msg);
})
.catch(function(error) {
console.error(error);
});