开发者

what does this mean? javascript question

var a = wi开发者_运维问答ndow.a || {};


It means a will be assigned window.a if it is not null or undefined, otherwise, it will equal an empty object


To answer the unasked question: this is used to make sure "a" will be valid.

Without it, when calling a.someFieldHere you might get exception saying "a is undefined", with such code in place you won't get such error.

It's useful when "a" is created elsewhere in some other code that not always get executed.

Kind of insurance policy. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜