编写短路条件的原因/好处是什么?
我正在搜索有关短路的很多信息,但是我对此代码有很大疑问。
const getClient = (userInfoContext) => {
const context = userInfoContext && userInfoContext.get()
const payload = context && context.payload && context.payload['www.payload.com']
return payload && payload.clientId
}
我想知道编写这样的代码而不是:
const getClient = (userInfoContext) => {
const context = userInfoContext.get()
const payload = context.payload['www.payload.com']
return payload.clientId
}
I was searching a lot about short circuit, but I have a big doubt with this code.
const getClient = (userInfoContext) => {
const context = userInfoContext && userInfoContext.get()
const payload = context && context.payload && context.payload['www.payload.com']
return payload && payload.clientId
}
I want to know what is the benefit of write the code like that instead of:
const getClient = (userInfoContext) => {
const context = userInfoContext.get()
const payload = context.payload['www.payload.com']
return payload.clientId
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论