Liking cljdoc? Tell your friends :D

Defclass

Since squint v0.1.15 is it possible to define JavaScript classes, using the defclass syntax. Here is an example that should show most of what is possible. The syntax is inspired by shadow-cljs.

(ns my-class
  (:require [squint.core :refer [defclass]]))

(defclass class-1
  (field -x)
  (field -y :dude) ;; default
  (^:static field a)
  (^:static field b :dude) ;; default
  (constructor [this x] (set! -x x))

  Object
  (get-name-separator [_] (str "-" -x))
  (^:static static-method [_] (str "static field: " a)))

(defclass Class2
  (extends class-1)
  (field -y 1)
  (constructor [_ x y]
               (super (+ x y)))

  Object
  (dude [_]
        (str -y (super.get-name-separator)))
  (^:async fetch [_]
    (js/fetch "https://clojure.org"))

  (toString [this] (str "<<<<" (.dude this) ">>>>") ))

(def c (new Class2 1 2))

Lit

See squint-lit-example on how to use squint together with lit. Or check out web-components-squint for a more elaborate example.

Can you improve this documentation? These fine people already did:
Michiel Borkent & Brandon Stubbs
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close