The deref
method returns the WeakRef
instance's target object, or undefined
if the target object has been garbage-collected.
Syntax
obj = ref.deref();
Return value
The target object of the WeakRef, or undefined
if the object has been garbage-collected.
Notes
See the Notes on WeakRefs section of the WeakRef
page for some important notes.
Examples
Using deref
See the Examples section of the WeakRef
page for the complete example.
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; } };
Specifications
Specification |
---|
WeakRefs The definition of 'WeakRef.prototype.deref()' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
deref | Chrome Full support 84 | Edge Full support 84 | Firefox Full support 79 | IE No support No | Opera No support No | Safari No support No | WebView Android Full support 84 | Chrome Android Full support 84 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs
Full support
13.0.0
|
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.
- User must explicitly enable this feature.