js-单体模式

时间:2019-06-29 14:34:45   收藏:0   阅读:94

实战使用场景,商城支付有港币,人民币,美元。根据用户的信息,设置币种的符号,在页面获取币种的符号。

let currencySymbol = {
    currency: ‘¥‘,
    get: function() {
      return this.currency
    },
    set: function(currency) {
      this.currency = currency
    }
  }
  console.log(currencySymbol.get())
  currencySymbol.set(‘%‘)
  console.log(currencySymbol)

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!