WeakRef.prototype.deref()
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.
Phương thức deref() của các instance WeakRef trả về giá trị target của WeakRef này, hoặc undefined nếu giá trị target đã được thu gom rác.
Cú pháp
js
deref()
Tham số
Không có.
Giá trị trả về
Giá trị target của WeakRef, là một đối tượng hoặc symbol không đăng ký. Trả về undefined nếu giá trị đã được thu gom rác.
Mô tả
Xem phần Ghi chú về WeakRef trên trang WeakRef để biết một số ghi chú quan trọng.
Ví dụ
>Sử dụng deref()
Xem phần Ví dụ trên trang WeakRef để có ví dụ đầy đủ.
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;
}
};
Đặc tả kỹ thuật
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-weak-ref.prototype.deref> |