过时
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.
handler.enumerate()
method used to be a trap for
for...in
statements, but has been removed from the ECMAScript standard in ES2016 and is deprecated in browsers.
var p = new Proxy(target, {
enumerate(target) {
}
});
The following parameter is passed to the
enumerate
方法。
this
is bound to the handler.
target
The target object.
An iterator 对象。
handler.enumerate
method is a trap for
for...in
语句。
This trap can intercept these operations:
for (var name in proxy) {...}
Reflect.enumerate()
If the following invariants are violated, the proxy will throw a
TypeError
:
enumerate
method must return an object.
The following code traps
for...in
语句。
var p = new Proxy({}, {
enumerate(target) {
console.log('called');
return ['a', 'b', 'c'][Symbol.iterator]();
}
});
for (var x in p) { // "called"
console.log(x); // "a"
} // "b"
// "c"
The following code violates the invariant.
var p = new Proxy({}, {
enumerate(target) {
return 1;
}
});
for (var x in p) {} // TypeError is thrown
Note: Both examples make use of the shorthand syntax for method definitions .
Not part of any standard.
Not supported anywhere. Historically supported in Firefox 37 till 46.
Proxy
handler
for...in
statements
Reflect.enumerate()
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()