单例模式 
单例模式的定义是:保证一个类仅有一个实例,并提供一个访问它的全局访问点。
单例模式是一种常用的模式,有一些对象我们往往只需要一个,比如线程池、全局缓存、浏览器中的window对象等。在JavaScript开发中,单例模式的用途同样非常广泛。试想一下,当我们单击登录按钮的时候,页面中会出现一个登录浮窗,而这个登录浮窗是唯一的,无论单击多少次登录按钮,这个浮窗都只会被创建一次,那么这个登录浮窗就适合用单例模式来创建。
代码
js
// video.mjs
class MyVideo {
  constructor(a, b) {
    this.a = a
    this.b = b
  }
  sayHi() {
    console.log('asdadwadw');
  }
}
function Singleton(className) {
  let ins
  return new Proxy(className, {
    construct(target, ...args) {
      if (!ins) {
        ins = new className(target, ...args) 
      }
      return ins
    }
  })
}
export default Singleton(MyVideo)js
// main.js
import MyVideo from './video.mjs'
const a = new MyVideo(1, 2)
const b = new MyVideo(3, 4)
console.log(a === b); // true