語法
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 |
瀏覽器相容性
載入中…