1

I'm following melon js tutorial. This is at the top of my HUD.js file.

game.HUD = game.HUD || {}

I've seen this before in other examples. What does the namespace.something = namespace.something || {} syntax mean and why is it needed?

4

1 回答 1

1

||是一个空合并运算符,因此您在该行中说如果它已经存在则返回我的对象​​,如果不存在则返回一个新对象(为空)

于 2014-03-05T22:38:56.410 回答