-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
60 lines (39 loc) · 1.69 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: WeakRef() コンストラクター
slug: Web/JavaScript/Reference/Global_Objects/WeakRef/WeakRef
l10n:
sourceCommit: 7da0dabee277f9c295178ae132c16c8fed5d747a
---
{{JSRef}}
**`WeakRef()`** コンストラクターは、 {{jsxref("WeakRef")}} オブジェクトを生成します。
## 構文
```js-nolint
new WeakRef(target)
```
> **メモ:** `WeakRef()` は [`new`](/ja/docs/Web/JavaScript/Reference/Operators/new) との組み合わせでのみ構築されます。 `new` 無しで呼び出そうとすると {{jsxref("TypeError")}} が発生します。
### 引数
- `target`
- : WeakRef の参照先となるターゲット値(リファレントとも呼ばれます)。オブジェクトまたは[未登録のシンボル](/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol#グローバルシンボルレジストリー)でなければなりません。
### 返値
指定されたターゲット地を参照する `WeakRef` オブジェクトです。
### 例外
- {{jsxref("TypeError")}}
- : `target` がオブジェクトまたは[未登録のシンボル](/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol#グローバルシンボルレジストリー)ではない場合に発生します。
## 例
### 新しい WeakRef オブジェクトの生成
完全な例は中心となる [`WeakRef`](/ja/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#例) ページを参照してください。
```js
class Counter {
constructor(element) {
// DOM 要素への弱い参照を覚える
this.ref = new WeakRef(element);
this.start();
}
}
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{jsxref("WeakRef")}}