过时
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.
Array.unobserve(arr, callback)
arr
The array to stop observing.
callback
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.
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
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
Archive
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.unwatch()
Object.prototype.valueOf()
Object.prototype.watch()
Object.setPrototypeOf()