Java脚本weakMap中的.clear()方法有什么用?

weakMap上的clear方法将从WeakMap对象中删除所有键/值对。

此方法已从规范中删除,可以通过包装WeakMap对象并添加对clear方法的支持来重新添加。

示例

class ClearableWeakMap {
   constructor(init) {
      this._wm = new WeakMap(init)
   }
   clear() {
      this._wm = new WeakMap()   }
   delete(k) {
   return this._wm.delete(k)
   }
   get(k) {
      return this._wm.get(k)
   }
   has(k) {
      return this._wm.has(k)
   }
   set(k, v) {
      this._wm.set(k, v)
   return this
   }
}