模块

function coolModule(){
        var something = 'cool';
        var another = [1,2,3];
    
        function doSome(){
            console.log(something);
        }
        function doanother(){
            console.log( another.join( " ! " ) );
        }

        return {
            dosome:doSome,
            doanother:doanother
        }
    }

    var obj = coolModule();
    obj.dosome();
    obj.doanother();

利用闭包的模块化

原文地址:https://www.cnblogs.com/jokes/p/9390065.html