Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil) . Junte-se a nós e ajude a fazer o trabalho!
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 handler.enumerate()
method used to be a trap for for...in
statements, but has been removed from the ECMAScript standard in edition 7 and is deprecated in browsers.
Syntax
var p = new Proxy(target, { enumerate(target) { } });
Parameters
The following parameter is passed to the enumerate
method. this
is bound to the handler.
target
- The target object.
Return value
An iterator object.
Description
The handler.enumerate
method is a trap for for...in
statements.
Interceptions
This trap can intercept these operations:
- Property enumeration / for...in:
for (var name in proxy) {...}
Reflect.enumerate()
Invariants
If the following invariants are violated, the proxy will throw a TypeError
:
- The
enumerate
method must return an object.
Examples
The following code traps for...in
statements.
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.
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of '[[Enumerate]]' in that specification. |
Standard | Initial definition. Removed in ECMAScript 2016 (ES7). |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | No support | No support [1] | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 37.0 (37) [1] | No support | No support | No support |
[1] This feature was supported from version 37 to version 46, but has been removed to comply with the latest ECMAScript standard, see bug 1246318.
See also
Proxy
handler
for...in
statementsReflect.enumerate()