ts模块与js模块

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/87906681

1) js模块

var jsModule = function () {
    var YQ = "123456";  // 没有var,但是依然是私有变量,外界不可访问
    return {
        add: function (t) {
            if(t>= 12){
                console.log("\n年费 =", t, "\nQQ群 =", YQ);
            }else{
                console.log("\n月费 =", t);
            }
        },

        setYQ: function (yq) {
            YQ = yq;
        }
    }
}

var jm = new jsModule();
jm.setYQ("111");
jm.add(12);



console.log(jm.YQ);

/**
 年费 = 12
 QQ群 = 111
 undefined
 */

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/87906681