Build an HTML5 game

This question already has an answer here:

  • What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript? 7 answers

  • || is the "or" operator in JavaScript. It returns the value on the left if the value on the left is truthy, otherwise it returns the value on the right.

    undefined and null , are both falsey values in JavaScript, so if window.BubbleShoot is one of these, the first line of your code will set the value of BubbleShoot to be {} , which is an empty JavaScript object on which you can set properties like Game as shown in your second line of code.


    The || is the JavaScript operator for 'OR', and the {} is defining a new, empty hash;

    Essentially, it's equivalent to the following:

    if (window.BubbleShoot != null && window.BubbleShoot != undefined) {
        BubbleShoot = window.BubbleShoot;
    } else {
        BubbleShoot = {}; // new, empty hash
    }
    
    链接地址: http://www.djcxy.com/p/95296.html

    上一篇: 我怎样才能传递参数给setTimeout()回调?

    下一篇: 构建一个HTML5游戏