← 返回首页
WeakRef() コンストラクター - JavaScript | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

WeakRef() コンストラクター

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021年4月.

* Some parts of this feature may have varying levels of support.

WeakRef() コンストラクターは、 WeakRef オブジェクトを生成します。

In this article

構文

js
new WeakRef(target)

メモ: WeakRef() は new との組み合わせでのみ構築されます。 new 無しで呼び出そうとすると TypeError が発生します。

引数

target

WeakRef の参照先となるターゲット値(リファレントとも呼ばれます)。オブジェクトまたは未登録のシンボルでなければなりません。

返値

指定されたターゲット地を参照する WeakRef オブジェクトです。

例外

TypeError

target がオブジェクトまたは未登録のシンボルではない場合に発生します。

新しい WeakRef オブジェクトの生成

完全な例は中心となる WeakRef ページを参照してください。

js
class Counter { constructor(element) { // DOM 要素への弱い参照を覚える this.ref = new WeakRef(element); this.start(); } }

仕様書

Specification
ECMAScript® 2027 Language Specification
# sec-weak-ref-constructor

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.

関連情報