(function () { //私有数据 var msg = 'my money' //操作数据的函数 function doSomething() { console.log('doSomething()' + msg.toUpperCase()) } function doOtherthing() { console.log('doOtherthing()' + msg.toLowerCase()) } //向外暴露对象(给外部使用的方法) window.myModule2 = { doSomething: doSomething, doOtherthing: doOtherthing } })() /* (function (window) { //私有数据 var msg = 'my money' //操作数据的函数 function doSomething() { console.log('doSomething()' + msg.toUpperCase()) } function doOtherthing() { console.log('doOtherthing()' + msg.toLowerCase()) } //向外暴露对象(给外部使用的方法) window.myModule2 = { doSomething: doSomething, doOtherthing: doOtherthing } })(window) //这种写法与上面的写法是一样的效果,但是这样写的好处是可以进行代码压缩 */