3

What is the alternative for the enumerate()

for JavaScript Proxy to trap

for ... in

Since enumerate() is deprecated.

user3840170
  • 26,597
  • 4
  • 30
  • 62
faressoft
  • 19,053
  • 44
  • 104
  • 146
  • What exactly is your use case? The [`ownKeys` trap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/ownKeys) should suffice – Bergi Jan 03 '17 at 13:43
  • see https://stackoverflow.com/a/45549376/1084004 – mikeapr4 Aug 07 '17 at 14:32

1 Answers1

0

Negatives make for unsatsifying answers, but unfortunately, I don't believe there's any direct replacement. Although the ownKeys trap will be triggered by a for-in loop (because its initialization uses the abstract EnumerateObjectProperties operation, which has to get the keys for an object via [[OwnPropertyKeys]]), ownKeys will also be triggered other times the keys of an object are required, not just when being used in a for-in loop.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875