2 回答
TA贡献2041条经验 获得超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,
}
此外,承诺的消费者应该有一个问题:
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贡献1875条经验 获得超3个赞
我通过以下方式解决:
const update = async (req, res) => {
// auxiliar method declaration
verifyItemInStock = itemId => {
// code...
}
// ...
// method call
const hasItems = verifyItemInStock(id)
}
添加回答
举报