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

Array.unobserve()

von 2 Mitwirkenden:
Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!

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.

The Array.unobserve() method is used to remove observers set by Array.observe().

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 Not supported Not supported 23 Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported 36 Not supported Not supported 23 Not supported

See also

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
Mitwirkende an dieser Seite: fscholz, Javascipt
Zuletzt aktualisiert von: fscholz,
Seitenleiste ausblenden