Reflection lets JavaScript inspect or influence the runtime representation of objects and their behavior. It belongs to metaprogramming: using code to automate, alter, or extend other code. JavaScript supports both static hooks through symbols and dynamic hooks through Proxy and Reflect. section 7.0 section 7.8
Reflection appears in two complementary forms:
- Static introspection adds symbols as object properties. Custom symbols create unique, collision-free extension points, while well-known symbols hook into operations such as iteration, spreading, primitive conversion, and printing. section 7.6 section 7.5
- Dynamic introspection changes behavior externally through Proxy and Reflect. These APIs intercept method calls or property access without adding injectable concerns to the target object's interface. section 7.6 section 7.8
- The separation is architectural: static extension changes an object's shape during construction, whereas dynamic weaving changes behavior during object use. section 7.6
A proxy as a reflective boundary
A proxy stands between client code and a target object. When a property is requested, the proxy can supply its own property or consult the target, making the boundary useful for logging, caching, masking, filesystem access, and network communication. The same mechanism supports method decorators and other cross-cutting behavior without polluting the wrapped object's interface. section 7.6 section 7.8
Figure 7.2 The Proxy pattern uses an object (proxy) to act on behalf of a target. When fetching for a property, if it finds the property in the proxy, the code uses that property; otherwise, it consults the target object. Proxies have lots of uses, including logging, caching, and masking.
Use the proxy diagram to trace how a client accesses a proxy first and how the proxy delegates to its target. section 7.6












