gpt4 book ai didi

javascript - MyApp如何检查 "typeof MyApp.User.current.language"

转载 作者:行者123 更新时间:2023-11-30 18:37:51 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
javascript test for existence of nested object key

if (typeof MyApp != 'undefined' &&
typeof MyApp.User != 'undefined' &&
typeof MyApp.User.current != 'undefined' &&
typeof MyApp.User.current.language != 'undefined') {

console.log(MyApp.User.current.language);
}

这感觉不对。这个 if 语句可以用更好的方式编写吗?

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