发布订阅-依赖于window

class Event {
  static fire(type, detail) {
    window.dispatchEvent(new CustomEvent(type, { detail }))
  }

  static on(type, callback) {
    return window.addEventListener(type, callback, false)
  }

  static off(type, callback) {
    window.removeEventListener(type, callback)
  }
}

export default Event

Last updated

Was this helpful?