WeakRef() 构造函数
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
* Some parts of this feature may have varying levels of support.
WeakRef()
会创建一个 WeakRef
对象,它是对于目标对象的弱引用。
语法
参数
targetObject
-
WeakRef 要指向的目标对象 (也称作 referent)。
示例
创建一个新的 WeakRef 对象
完整的示例请见 WeakRef
主页面。
js
class Counter {
constructor(element) {
// 创建一个对 DOM 元素的弱引用
this.ref = new WeakRef(element);
this.start();
}
}
规范
Specification |
---|
ECMAScript® 2026 Language Specification # sec-weak-ref-constructor |