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();

 

posted @ 2020-04-27 18:32  .Neterr  阅读(215)  评论(0编辑  收藏  举报