gpt4 book ai didi

javascript - 在整个变量表达式周围有 () 的这个 javascript 语法是什么?

转载 作者:可可西里 更新时间:2023-11-01 02:34:01 25 4
gpt4 key购买 nike

({ body: { customer } } = await callCreateCustomer({
email: createRandomEmailAddress(),
key: 999,
password: 'password',
}));

我不明白当你在整个表达式周围使用 () 是什么意思?

它有什么作用?

最佳答案

这是没有声明的解构赋值。这里 customer 变量已经在上面声明,并且正在使用 response.body.customer

分配一个值

来自documentation :

The parentheses ( ... ) around the assignment statement are required when using object literal destructuring assignment without a declaration.

{a, b} = {a: 1, b: 2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.

However, ({a, b} = {a: 1, b: 2}) is valid, as is var {a, b} = {a: 1, b: 2}

Your ( ... ) expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.

关于javascript - 在整个变量表达式周围有 () 的这个 javascript 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com