Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Array.unobserve()

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The Array.unobserve() method was used to remove observers set by Array.observe(), but has been deprecated and removed from Browsers. You can use the more general Proxy object instead.

Syntax

Array.unobserve(arr, callback)

Parameters

arr
The array to stop observing.
callback
The reference to the observer to stop calling each time changes are made on the array arr.

Description

Array.unobserve() should be called after Array.observe() in order to remove an observer from an array.

The callback should be a reference to a function and not an anonymous function, because this reference will be used to unset the previous observer. It's useless to call Array.unobserve() with an anonymous function as callback, it will not remove any observer.

Examples

Unobserving an array

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();
// The callback wasn't called

Using an anonymous function

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 }]
// The callback will always be called

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 36 [1] No support No support 23 No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support 36 [1] No support No support 23 No support

[1] Deprecated in Chrome 49.

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz, Javascipt
 최종 변경: fscholz,