js-单体模式

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

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

  

猜你喜欢

转载自www.cnblogs.com/fm060/p/11106283.html