是什么“对象|| {}“在javascript中意味着什么? [英] what does "object || {} " means in javascript?
本文介绍了是什么“对象|| {}“在javascript中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在javascript应用程序中找到了以下代码行。
I found below line of code in javascript application.
var auth = parent.auth = parent.auth || {};
我知道现有的Object父级用auth Object扩展但我不明白什么是 parent.auth || {}
在这里做。
I know there is existing Object parent which is extended with auth Object but i don't understand what is parent.auth || {}
doing here.
推荐答案
parent.auth || {}
表示如果 parent.auth
未定义,在布尔值情况下为null或false,则初始化并分配新的空对象。
parent.auth || {}
means if parent.auth
is undefined, null or false in boolean case then new empty object will be initialized and assigned.
或者您可以理解为:
var auth;
if(parent.auth){
auth=parent.auth;
} else {
auth={};
}
这篇关于是什么“对象|| {}“在javascript中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文