Skip to content
Matt Huebert edited this page Feb 28, 2019 · 4 revisions

Extending the global object

It's possible to implement ILookup for "all" JavaScript objects, as explained by Mike Fikes here. This will only have an effect on plain objects whose prototype is js/Object, not for any other kind of object (eg. it won't work for browser events or React components). It also mutates the global js/Object.

How it's done:

Associative destructuring is based on get, which can be mapped onto goog.object/get for JavaScript objects by extending them to ILookup:

(extend-type object
 ILookup
 (-lookup 
  ([o k] 
    (goog.object/get o (name k)))
  ([o k not-found] 
    (goog.object/get o (name k) not-found))))
Clone this wiki locally