★ wanayoo — archive 1999 https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/unobserveNouvelle recherche | Portail wanayoo

Array.unobserve

by 1 contributor:

This article is in need of an editorial review.

This is an experimental technology, part of the ECMAScript 2016 (ES7) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

Array.unobserve()メソッドは、。Array.observe()で設定された監視を削除するために使われます

構文

Array.unobserve(arr, callback)

パラメーター

arr
監視を停止する配列。
callback
arr配列の変更毎に呼び出されるのを停止する監視への参照。

説明

配列から監視を削除するために、Array.unobserve() はArray.observe() の後に呼び出される必要があります。

callbackは、関数への参照であり、匿名関数ではいけません。なぜなら、この参照は以前の監視を解除するために使われるかもしれないからです。callbackとして匿名関数を使った場合、監視を削除できないので、Array.unobserve() 呼び出しは無意味です。

例

配列監視の削除

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は呼び出されない。

匿名関数の使用

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は常に呼び出される。

ブラウザ実装状況

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 36 未サポート 未サポート 23 未サポート
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未サポート 36 未サポート 未サポート 23 未サポート

関連項目

ドキュメントのタグと貢献者

Contributors to this page: YuichiNukiyama
最終更新者: YuichiNukiyama,
サイドバーを隠す