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
Specification |
---|
WeakRefs The definition of 'WeakRef constructor' in that specification. |
Browser compatibility
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.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WeakRef() constructor | Chrome Full support 84 | Edge Full support 84 | Firefox Full support 79 | IE No support No | Opera No support No | Safari No support No | WebView Android Full support 84 | Chrome Android Full support 84 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs
Full support
13.0.0
|
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.
- User must explicitly enable this feature.