O'Reilly logo

Rediscovering JavaScript by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Synthesizing Members with Proxy

In Injecting Multiple Properties we injected the first and last properties into instances of Array so we could fluently get the first and last elements of an array. We came up with property names like first and last at the time of metaprogramming, but on many occasions we may want to devise property or method names at runtime based on the execution context or state of an object. In other words, we may not know the name of a property to be injected at code writing time—it comes to life at runtime.

To practice method synthesis, let’s create an example to use a Map that holds an associative set of keys and values of languages and authors.

 const​ langsAndAuthors = ​new​ Map([
  [​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required