aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/workerglobalscope/self/index.html
blob: 5d951e14485f4008853fb4ddca2364e5dd7fec12 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: WorkerGlobalScope.self
slug: Web/API/WorkerGlobalScope/self
tags:
  - API
  - Property
  - Reference
  - Web Worker
  - WorkerGlobalScope
  - self
translation_of: Web/API/WorkerGlobalScope/self
---
<div>{{APIRef("Web Workers API")}}</div>

<p>{{domxref("WorkerGlobalScope")}} インターフェースの <code><strong>self</strong></code> 読み取り専用プロパティは、<code>WorkerGlobalScope</code> 自体への参照を返します。ほとんどの場合、これは {{domxref("DedicatedWorkerGlobalScope")}}{{domxref("SharedWorkerGlobalScope")}}{{domxref("ServiceWorkerGlobalScope")}} などの特定のスコープです。</p>

<h2 id="構文">構文</h2>

<pre class="brush: js">var selfRef = self;</pre>

<h3 id="値"></h3>

<p>グローバルスコープオブジェクト (上に示したように、扱っている worker の種類によって異なる)。</p>

<h2 id="例"></h2>

<p>以下を呼び出した場合、</p>

<pre class="brush: js">console.log(self);</pre>

<p>worker 内で、コンソールに書き込まれたワーカーオブジェクトと同じタイプのワーカーグローバルスコープが取得されます — ある時は次のようになります:</p>

<pre class="brush: js">DedicatedWorkerGlobalScope {
undefined: undefined, Infinity: Infinity, Math: MathConstructor, NaN: NaN, Intl: Object…}
    Infinity: Infinity
    Array: function Array() { [native code] }
      arguments: null
      caller: null
      isArray: function isArray() { [native code] }
      length: 1
      name: "Array"
      observe: function observe() { [native code] }
      prototype: Array[0]
      unobserve: function unobserve() { [native code] }
      __proto__: function Empty() {}
      &lt;function scope&gt;
    ArrayBuffer: function ArrayBuffer() { [native code] }
    Blob: function Blob() { [native code] }
    Boolean: function Boolean() { [native code] }
    DataView: function DataView() { [native code] }
    Date: function Date() { [native code] }
    DedicatedWorkerGlobalScope: function DedicatedWorkerGlobalScope() { [native code] }
    Error: function Error() { [native code] }
<em>// etc. etc.</em>
</pre>

<p>これは、そのワーカースコープで利用可能なオブジェクトの完全なリストを提供するため、ワーカーが何かを利用できるかを確認したい場合には、非常に便利なテストです。リストを<a href="/ja/docs/Web/API/Worker/Functions_and_classes_available_to_workers">Web Workers が使用できる関数とクラス</a>でもメンテナンスしています。</p>

<div class="note">
<p><strong>ノート</strong>: Firefox には <code>console.log</code> を shared/service worker 内で使用したときのバグがあり ({{Bug("1058644")}} を見てください)、おかしな結果を返します。これはすぐに修正されるはずです。</p>
</div>

<h2 id="仕様">仕様</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">仕様</th>
   <th scope="col">ステータス</th>
   <th scope="col">コメント</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', '#dom-workerglobalscope-self', 'self')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>{{SpecName("Web Workers")}} から変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName('Web Workers', '#dom-workerglobalscope-self', 'self')}}</td>
   <td>{{Spec2('Web Workers')}}</td>
   <td>初期定義。</td>
  </tr>
 </tbody>
</table>

<h2 id="ブラウザー実装状況">ブラウザー実装状況</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>機能</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>基本サポート</td>
   <td>{{CompatChrome(4)}}</td>
   <td>{{CompatGeckoDesktop("1.9.1")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>11.5</td>
   <td>4</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>機能</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>基本サポート</td>
   <td>{{CompatUnknown}}</td>
   <td>40</td>
   <td>{{CompatGeckoMobile("1.9.1")}}</td>
   <td>1.0.1</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>5.1</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="関連項目">関連項目</h2>

<p>{{domxref("WorkerGlobalScope")}}</p>