Documentación offline JavaScript main

WeakRef.prototype.deref()

main Documentación oficial Licencia CC-BY-SA-2.5Descargado el 2026-08-02

En esta página

The deref() method of {{jsxref("WeakRef")}} instances returns this WeakRef's target value, or undefined if the target value has been garbage-collected.

Syntax#

deref()

Parameters#

None.

Return value#

The target value of the WeakRef, which is either an object or a non-registered symbol. Returns undefined if the value has been garbage-collected.

Description#

See the Notes on WeakRefs section of the {{jsxref("WeakRef")}} page for some important notes.

Examples#

Using deref()#

See the Examples section of the {{jsxref("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#

{{Specifications}}

Browser compatibility#

{{Compat}}

See also#

  • {{jsxref("WeakRef")}}