WeakRef constructor creates a WeakRef object referring to a given target object.

句法

new WeakRef(targetObject);
					

参数

targetObject
The target object the WeakRef should refer to (also called the referent ).

范例

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();
  }
}
					

规范

规范
WeakRefs
The definition of 'WeakRef constructor' in that specification.

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
WeakRef() 构造函数 Chrome 84 Edge 84 Firefox 79 IE No Opera No Safari No WebView Android 84 Chrome Android 84 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No nodejs 13.0.0 Disabled
13.0.0 Disabled
Disabled From version 13.0.0: this feature is behind the --harmony-weak-refs runtime flag.

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: