WeakRef() constructor

The WeakRef constructor creates a WeakRef object referring to a given target object.

Syntax

new WeakRef(targetObject);

Parameters

targetObject
The target object the WeakRef should refer to (also called the referent).

Examples

Creating a new WeakRef object

See the main WeakRef page for a complete example.

class Counter {
  constructor(element) {
    // Remember a weak reference to a DOM element
    this.ref = new WeakRef(element);
    this.start();
  }
}

Specifications

Browser compatibility

BCD tables only load in the browser

See also