2 回答

TA貢獻(xiàn)2041條經(jīng)驗 獲得超4個贊
刪除this并使其更具可讀性:
// method declaration
const verifyItemInStock = itemId => {
// more code...
}
const update = async (req, res) => {
// code here...
// method call
verifyItemInStock()
// more code here ...
}
module.exports = {
update,
verifyItemInStock,
}
此外,承諾的消費者應(yīng)該有一個問題:
import { update } from './my-module';
update(req, res).then(...).catch(...)
// or
try {
const resolved = await update(req, res);
// consume the resolved value
} catch (e) {
// exception handling
}

TA貢獻(xiàn)1875條經(jīng)驗 獲得超3個贊
我通過以下方式解決:
const update = async (req, res) => {
// auxiliar method declaration
verifyItemInStock = itemId => {
// code...
}
// ...
// method call
const hasItems = verifyItemInStock(id)
}
添加回答
舉報