📕
blog
  • Hi there
  • javascript
    • 柯里化 - Curry
    • 观察者和订阅-发布模式
    • generator
    • 发布订阅-依赖于window
    • pwa manual trigger install
  • browser
    • beautify scrollbar
  • http
    • nginx 缓存配置
  • extra
    • vue-cli 不使用 .env[.xxx] 文件,添加额外运行时参数
    • docker-compose nginx with ssl config
  • React
    • How React works
Powered by GitBook
On this page

Was this helpful?

  1. javascript

发布订阅-依赖于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
PreviousgeneratorNextpwa manual trigger install

Last updated 4 years ago

Was this helpful?