JS设计模式_单例模式

    const cool = (function () {
      let something = 'cool'
      let another = [1,2,3]
      function dosomeThing() {
          console.log(something)
      }
      function doAnother() {
          console.log(another.join('-'))
      }
      return{
          dosomeThing,
          doAnother
      }
    }())
    cool.doAnother() // 1-2-3
    cool.doAnother() // 1-2-3

你可能感兴趣的:(JS设计模式_单例模式)