【发布时间】:2020-03-31 16:31:00
【问题描述】:
这是我已经拥有的:
myFunct({ myObj: { db } })
我需要添加另一个功能,例如:
myFunct({ myObj: async ({ req }) => {
//more scripts
} })
我尝试过但失败了:
myFunct({ myObj: {
db,
async (req) => {
//more scripts
}
} })
在 => 我得到语法错误:
Unexpected token, expected {
【问题讨论】:
-
它不起作用,因为您没有命名将保存该函数的属性。
{ db }语法是声明与标识符同名的属性用作值的简写,例如:{ db: db }。 -
我知道这很容易被我忽略。尝试将我的编程语言从 php 切换到 node 带来了一系列挑战。
标签: javascript function ecmascript-6 async-await syntax-error