Var something = somethingElse.obj = somethingElse.obj || {} - what is it used for?

Sorry for the strange name ... not sure how else to find out about a language feature like this.

I read about module templates when I came across this example, when I came across this line of code. This happens in closing for an example module template for saving private state in different files, when the module “weakly supplements”.

EDIT - Included the rest of the module code

var MODULE = (function (my) { 
    var _private = my._private = my._private || {}, 
        _seal = my._seal = my._seal || function () { 
            delete my._private; 
            delete my._seal; 
            delete my._unseal; 
        }, 
        _unseal = my._unseal = my._unseal || function () { 
            my._private = _private; 
            my._seal = _seal; 
            my._unseal = _unseal; 
        }; 

    // permanent access to _private, _seal, and _unseal 

    return my; 
}(MODULE || {}));

I tried to break it, but it does not add up.

. beore var someVar = something || somethingElse, , - (false, null ..), (, ).

, . , my._private , ... .

my._private ?

+3
3

, Javascript , ( , ).

foo = bar = 3;

foo = (bar = 3);

bar = 3;
foo = 3;

my._private {}, false, _private

+2

:

var _private = my._private = my._private || {};

my._private, _private.

, my._private _private .


? , - ... , .

0

? , . var _private = my._private || {};

0

Source: https://habr.com/ru/post/1778783/


All Articles