A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref below:

WeakRef.prototype.deref() - JavaScript | MDN

WeakRef.prototype.deref()

Baseline Widely available

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

Syntax 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 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 Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4