myModule2.js 989 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. (function () {
  2. //私有数据
  3. var msg = 'my money'
  4. //操作数据的函数
  5. function doSomething() {
  6. console.log('doSomething()' + msg.toUpperCase())
  7. }
  8. function doOtherthing() {
  9. console.log('doOtherthing()' + msg.toLowerCase())
  10. }
  11. //向外暴露对象(给外部使用的方法)
  12. window.myModule2 = {
  13. doSomething: doSomething,
  14. doOtherthing: doOtherthing
  15. }
  16. })()
  17. /* (function (window) {
  18. //私有数据
  19. var msg = 'my money'
  20. //操作数据的函数
  21. function doSomething() {
  22. console.log('doSomething()' + msg.toUpperCase())
  23. }
  24. function doOtherthing() {
  25. console.log('doOtherthing()' + msg.toLowerCase())
  26. }
  27. //向外暴露对象(给外部使用的方法)
  28. window.myModule2 = {
  29. doSomething: doSomething,
  30. doOtherthing: doOtherthing
  31. }
  32. })(window)
  33. //这种写法与上面的写法是一样的效果,但是这样写的好处是可以进行代码压缩
  34. */