var event = {
    items: {},
    on: function (type, fn) {
        if (!this.items[type]) {
            this.items[type] = []
        }
        this.items[type].push(fn)
    },
    emit: function (type) {
        for (var i in this.items) {
            if (i == type) {
                this.items[type].forEach(fn => fn())
            }
        }
    },
    off: function (type) {
        if (type) {
            delete this.items[type]
        } else {
            this.items = {}
        }
    }
}

 

相关文章:

  • 2021-09-04
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-01-06
  • 2021-07-06
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-12-28
  • 2021-07-31
  • 2021-12-05
相关资源
相似解决方案