W3cubDocs

/JavaScript

WeakRef.weakRef

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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
WeakRef() constructor 84 84 79 No No No
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
WeakRef() constructor 84 84 79 No No No
Server
Node.js
WeakRef() constructor 13.0.0
Disabled
13.0.0
Disabled
Disabled From version 13.0.0: this feature is behind the --harmony-weak-refs runtime flag.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/WeakRef