WeakRef() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The WeakRef()
constructor creates WeakRef
objects.
Syntax
Parameters
target
-
The target value the WeakRef should refer to (also called the referent). Must be an object or a non-registered symbol.
Return value
A new WeakRef
object referring to the given target value.
Exceptions
TypeError
-
Thrown if
target
is not an object or a non-registered symbol.
Examples
Creating a new WeakRef object
See the main WeakRef
page for a complete example.
js
class Counter {
constructor(element) {
// Remember a weak reference to a DOM element
this.ref = new WeakRef(element);
this.start();
}
}
Specifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weak-ref-constructor |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WeakRef() constructor |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.