MDN will be in maintenance mode on Friday September 22nd, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.

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 Object.unobserve() method was used to remove observers set by Object.observe(), but has been deprecated and removed from Browsers. You can use the more general Proxy object instead.

Syntax

Object.unobserve(obj, callback)

Parameters

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

Return value

The specified object.

Description

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

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 Object.unobserve() with an anonymous function as callback, it will not remove any observer.

Examples

Unobserving an object

var obj = {
  foo: 0,
  bar: 1
};

var observer = function(changes) {
  console.log(changes);
}

Object.observe(obj, observer);
​
obj.newProperty = 2;
// [{name: 'newProperty', object: <obj>, type: 'add'}]

Object.unobserve(obj, observer);

obj.foo = 1;
// The callback wasn't called

Using an anonymous function

var person = {
  name: 'Ahmed',
  age: 25
};

Object.observe(person, function(changes) {
  console.log(changes);
});

person.age = 40; 
// [{name: 'age', object: <obj>, oldValue: 25, type: 'update'}]

Object.unobserve(person, function(changes) {
  console.log(changes);
});

person.age = 63;
// [{name: 'age', object: <obj>, oldValue: 40, type: 'update'}]
// The callback will always be called

Specifications

Strawman proposal specification.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support36 — 52 No No No No No
FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support No No No No No No No

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz, nmve, eduardoboucas, x2357, Javascipt, youssef06, aminembarki
 최종 변경: fscholz,