exports.index = function(req, res) {
moviedb.indexMovie()
.then(x => {
Movie.findAsync()
.then(responseWithResult(res))
.catch(handleError(res))
}
)
};
function responseWithResult(res, statusCode) {
statusCode = statusCode || 200;
console.log("Populating Response");
return function(entity) {
if (entity) {
res.status(statusCode).json(entity);
}
};
}
上面的代碼工作得很好,responsewithresult函數中的返回函數使用.then響應填充。但是,我正在嘗試並嘗試這個,但它沒有奏效。請解釋爲什麼?然後調用Javascript匿名函數
exports.index = function(req, res) {
moviedb.indexMovie()
.then(x => {
Movie.findAsync()
.then(x => {responseWithResult(res)}) // <-- this doesn't work
.catch(handleError(res))
})
};
我得到了第一部分。但是,請您詳細說明「不按序列操作」的含義。 – shiv
@本傑明是正確的。請參閱文檔示例:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Shorter_functions – Nirus
我現在瞭解箭頭操作位。本傑明談到的排序是什麼?我該怎麼做,有什麼好處? – shiv