javascript / latest / global_objects / weakref / weakref.html /

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

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet Deno Node.js
WeakRef
84
84
79
No
No
14.1
84
84
79
No
14.5
14.0
1.0
14.6.0
13.0.0

See also

© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/WeakRef