语法
js
deref()
参数
无。
返回值
WeakRef 的目标值,可以是对象或 未注册的 Symbol。如果值已被垃圾回收,则返回 undefined。
描述
有关一些重要说明,请参阅 WeakRef 页面的 关于 WeakRefs 的说明 部分。
示例
使用 deref()
js
const tick = () => {
// Get the element from the weak reference, if it still exists
const element = this.ref.deref();
if (element) {
element.textContent = ++this.count;
} else {
// The element doesn't exist anymore
console.log("The element is gone.");
this.stop();
this.ref = null;
}
};
规范
| 规范 |
|---|
| ECMAScript® 2026 语言规范 # sec-weak-ref.prototype.deref |
浏览器兼容性
加载中…