首页 > 代码库 > javascript 模块快学习

javascript 模块快学习

<script>
    var Module = (function () {
        var my = {};
        function privateMethod() {

        }
        my.moduleProperty = 1;
        my.moduleMethod = function () { }

        return my;
    } ());       //为防止修改内部的变量

    console.log(Module.moduleProperty);//1
    Module.moduleMethod = 2;
    console.log(Module.moduleProperty);//1
</script>