The WeakRef() constructor creates WeakRef objects.
new WeakRef(target)Note: WeakRef() can only be constructed with new. Attempting to call it without new throws a TypeError.
targetThe target value the WeakRef should refer to (also called the referent). Must be an object or a non-registered symbol.
A new WeakRef object referring to the given target value.
TypeErrorThrown if target is not an object or a non-registered symbol.
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();
}
}