blob: 96c9cd5e4d2657e03a92de26e47a1e1d13af1b2a (
plain)
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
|
---
title: CustomElementRegistry.get()
slug: Web/API/CustomElementRegistry/get
tags:
- API
- CustomElementRegistry
- 実験的
- メソッド
- リファレンス
- ウェブコンポーネント
- カスタム要素
- get
browser-compat: api.CustomElementRegistry.get
---
{{APIRef("CustomElementRegistry")}}
**`get()`** は {{domxref("CustomElementRegistry")}} インターフェイスのメソッドで、以前定義したカスタム要素のコンストラクターを返します。
## 構文
```js
constructor = customElements.get(name);
```
### 引数
- name
- : コンストラクターの参照を返したいカスタム要素の名前です。
### 返値
名前付きのカスタム要素のコンストラクター、またはその名前のカスタム要素がない場合は `undefined` です。
## 例
```js
customElements.define('my-paragraph',
class extends HTMLElement {
constructor() {
let templateContent = document.getElementById('my-paragraph').content;
super() // このスコープの要素を返す
.attachShadow({mode: 'open'}) // this.shadowRoot を設定して返す
.append(templateContent.cloneNode(true));
}
})
// my-paragraph のコンストラクターの参照を返す
let ctor = customElements.get('my-paragraph');
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
|