【发布时间】:2014-03-12 20:54:32
【问题描述】:
var Q = require("q");
function test(v){
var deferred = Q.defer()
if (v) {
console.log("success");
deferred.resolve();
}
else{
console.log("failed");
deferred.reject(new Error("failed"))
}
return deferred.promise;
}
var over = function(url){
console.log("hahaha")
console.log(url)
}
var failed = function(){
console.log("wuwuw")
}
test().then(over, failed)
test().then(over("localhost"), failed)
test().then(over, failed)时,function over不应该执行,程序可以做的很好,
我可以得到结果:
failed
wuwuw
但是当我为函数结束添加参数时,函数结束将执行。我会得到:
failed
hahaha
localhost
wuwuw
显然,我不希望函数过度执行,但我需要它在 test() 解析时获取参数。
【问题讨论】: