Skip to main content
100%

JS Class __proto__ Proxy

✓ Published0🌍 Public
NN0taN3rd
Last edited Jul 24, 2017
Created on Jul 24, 2017

This example demonstrates a JavaScript class that uses a Proxy to create a counter with automatic default values and type enforcement. The `Counter` class wraps a plain object in a `Proxy`, intercepting `get` operations to initialize missing keys to zero and `set` operations to reject non-numeric values. It provides iterator methods like `entries`, `sortedEntries`, and `sorted` for retrieving and ordering the counted data, using standard JavaScript iterators and `Object.entries`. The code relies solely on native JavaScript APIs, including the `Proxy` traps `get`, `set`, `has`, `ownKeys`, and `getOwnPropertyDescriptor`.

AI-generated description

Similar vizzes