Synthesizing Members Directly on an Instance
Learn how to synthesize members directly on instances of a class instead of a proxy.
We'll cover the following...
The two pillars
Rather than calling proxy.key
, we should be able to perform anyInstanceOfMap.key
. To achieve this, we need to bring two different pieces of knowledge together.
-
First, when a nonexistent property is requested on an object, JavaScript automatically requests it from the object’s prototype. If the prototype does not have it, the search continues through the prototype chain—see Understanding Prototypal Inheritance.
-
Second, a proxy can trap requests for properties, fields, and methods, among other things—in essence, the details we have explored in this chapter.
Combining the two pieces
Let’s combine these two pieces of knowledge to create a powerful synthesis.
- If a property or a method exists, we simply want