这个原始javascript有效:
function newStatusEvent(account, eventId, url, deferred, iteration) {
var iteration = typeof iteration !== 'undefined' ? iteration : 0;
url.get()
.then(function(data) {
console.log(data);
if (data.Automation.Status != "COMPLETED") {
if (iteration < CHECK_ITERATIONS) {
iteration++;
$timeout(function (){
newStatusEvent(account, eventId, url,
deferred, iteration);
}, TIME_ITERATION);
} else {
deferred.reject("failure");
}
} else {
deferred.resolve("complete");
}
});
return deferred.promise;
}
但是在coffeescript中:
newStatusEvent = (account, eventId, url, deferred, iteration) ->
iteration = (if typeof iteration isnt "undefined" then iteration else 0)
url.get().then (data) ->
console.log(data)
unless data.Automation.Status is "COMPLETED"
if iteration < CHECK_ITERATIONS
iteration++
$timeout (->
newStatusEvent account, eventId, url, deferred, iteration
return
), TIME_ITERATION
else
deferred.reject "failure"
else
deferred.resolve "complete"
return
deferred.promise
data
url.get().then (data) ->
未定义。另外,coffeescript版本没有将承诺对象的结果... data
传递给.then()
方法。我想这是一个咖啡脚本的东西,因为它在javascript中工作。到底是怎么回事?