gpt4 book ai didi

javascript - 避免表达式中使用分号的最佳方法

转载 作者:行者123 更新时间:2023-11-28 18:48:21 25 4
gpt4 key购买 nike

我有这样的场景:

updates['errmsg'] = data.errmsg;
((!data.question) ? (this.unset('question')) : updates['question'] = data.question)
updates['run_time'] = data.run_time

我试图避免第一行上的分号,但是,当我省略它时,下面的行会加入上一行,并且我收到错误,因为 data.errmsg 不是函数。如何在第二行使用表达式,而不在第一行使用分号?

最佳答案

跳过括号

!data.question ? this.unset('question') : (updates['question'] = data.question)

关于javascript - 避免表达式中使用分号的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34943176/

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