Javascript使用函数做命名空间

js中只有函数有作用域,所以用函数模拟一个命名空间

function CartNamespace(){

    function LoginBox(){/*登录弹窗*/
        this.show=function(){};
    }

    function ShopCartBusiness(){/*购物车业务*/
        var _loginBox = undefined;

        this.init=function(){
            _loginBox = new LoginBox();
        };
    }
    this.shopCart=new ShopCartBusiness();
}


var shopCart = new CartNamespace().shopCart;
shopCart.init();
原文地址:https://www.cnblogs.com/fanfan-90/p/12788748.html