/*** 自定义模块1*/ function coolModule() {//私有的数据var msg = 'atguigu'var names = ['I', 'Love', 'you']//私有的操作数据的函数function doSomething() {console.log(msg.toUpperCase())}function doOtherthing() {console.log(names.join(' '))}//向外暴露包含多个方法的对象return {doSomething: doSomething,doOtherthing: doOtherthing} } <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>05_闭包的应用_自定义JS模块</title> </head> <body> <!-- 闭包的应用2 : 定义JS模块* 具有特定功能的js文件* 将所有的数据和功能都封装在一个函数内部(私有的)* 只向外暴露一个包信n个方法的对象或函数* 模块的使用者, 只需要通过模块暴露的对象调用方法来实现对应的功能 --> <script type="text/javascript" src="05_coolModule.js"></script> <script type="text/javascript">var module = coolModule()module.doSomething()module.doOtherthing() </script> </body> </html>