JavaScript Snippet
Proxy Patterns: Validation, Logging, Defaults
Difficulty: Hard
`Proxy` lets you intercept the basic operations on an object (get, set, has, deleteProperty) and run your own logic before or instead of the default behavior. This snippet shows three of the most useful patterns: a validating Proxy that rejects bad writes at the source, a logging Proxy that records access for debugging, and a defaults-plus-locked Proxy that supplies fallbacks and freezes keys after init. Use sparingly because Proxy adds a small per-access cost; reach for it when you need cross-cutting policy on a plain data object.
