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
|
---
title: Array.unobserve
slug: Web/JavaScript/Reference/Global_Objects/Array/unobserve
tags:
- Array
- JavaScript
- Method
- Obsolete
translation_of: Archive/Web/JavaScript/Array.unobserve
---
<div>{{JSRef}} {{obsolete_header}}</div>
<p>Array<strong>.unobserve()</strong>メソッドは、{{jsxref("Array.observe()")}} で設定された監視を削除するために使われていましたが、非推奨となりブラウザから削除されました。代わりに、一般的な {{jsxref("Proxy")}} オブジェクトを使用してください。</p>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox">Array.unobserve(<var>arr</var>, <var>callback</var>)</pre>
<h3 id="Parameters" name="Parameters">引数</h3>
<dl>
<dt><code>arr</code></dt>
<dd>監視を停止する配列。</dd>
<dt><code>callback</code></dt>
<dd><strong>arr</strong> 配列の変更時に毎回呼び出されるのを停止するための、オブザーバへの参照。</dd>
</dl>
<h2 id="Description" name="Description">説明</h2>
<p>配列からオブザーバを削除するため、<code>Array.unobserve()</code> は {{jsxref("Array.observe()")}} の後に呼び出される必要があります。</p>
<p>callback は関数への参照とすべきであり、匿名関数ではいけません。なぜなら、この参照は以前のオブザーバを解除するために使用されるからです。callback として匿名関数を使った <strong>Array.unobserve()</strong> の呼び出しは、オブザーバを削除できないので無意味です。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Unobserving_an_array" name="Unobserving_an_array">配列の監視を削除</h3>
<pre class="brush: js">var arr = [1, 2, 3];
var observer = function(changes) {
console.log(changes);
}
Array.observe(arr, observer);
arr.push(4);
// [{type: "splice", object: <arr>, index: 3, removed:[], addedCount: 1}]
Array.unobserve(arr, observer);
arr.pop();
// callback は呼び出されなかった。</pre>
<h3 id="Using_an_anonymous_function" name="Using_an_anonymous_function">匿名関数の使用</h3>
<pre class="brush: js">var persons = ['Khalid', 'Ahmed', 'Mohammed'];
Array.observe(persons, function (changes) {
console.log(changes);
});
persons.shift();
// [{type: "splice", object: <arr>, index: 0, removed: [ "Khalid" ], addedCount: 0 }]
Array.unobserve(persons, function (changes) {
console.log(changes);
});
persons.push('Abdullah');
// [{type: "splice", object: <arr>, index: 2, removed: [], addedCount: 1 }]
// callback は常に呼び出される。
</pre>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2>
<div>{{CompatibilityTable}}</div>
<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("36")}} [1]</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatOpera("23")}}</td>
<td>{{CompatNo}}</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>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>基本サポート</td>
<td>{{CompatNo}}</td>
<td>{{CompatChrome("36")}} [1]</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatOpera("23")}}</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] Chrome 49 で非推奨になりました。</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Array.observe()")}} {{obsolete_inline}}</li>
<li>{{jsxref("Object.observe()")}} {{obsolete_inline}}</li>
<li>{{jsxref("Object.unobserve()")}} {{obsolete_inline}}</li>
</ul>
|