Reflection—Reflect and Proxy
T.J. Crowder · 2020
This chapter discusses the Reflect object, which provides a host of useful utility features for constructing and interacting with objects, and Proxy object, which provides the ultimate façade pattern for JavaScript—a pattern that can be important for providing application programming interfaces to client code. Reflect.apply is a utility function that does what the apply method on functions does. Reflect.construct creates a new instance via a constructor function, like the new operator does. The Reflect.ownKeys function is superficially similar to Object.keys, but returns an array of all of the object's own property keys. Reflect.get and Reflect.set functions get and set properties on an object. The chapter presents an example of a logging proxy, logging all of the fundamental operations that occur on an object. It describes each of the proxy traps in the logging example, including any limitations on the traps.