Skip to content

Selecting class instances ​

Class instances in JavaScript are created using the new keyword. In SYNG, (of) selects such instantiations, which has a form similar to that of (call) that we've already seen.

(of) has the following signature:

clojure
(of [class] [args])

Selecting by class ​

The first argument to (of) accepts any valid JavaScript expression, not only class declarations or expressions, since technically any object that has a prototype with a constructor function can be instantiated using new.

For example, to select all instances of a Promise:

clojure
(of Promise)

Which would match new Promise().

Selecting by arguments ​

The second argument to (of) behaves exactly like the one for (call), so you can refer to it for more information. For example, to select a Promise that was created with only a resolution handler:

clojure
(of Promise
    (:and (arg 1)
          (:not (arg 2))))

Copyright © 2022-present Semantic Works, Inc.