Skip to content

Instantly share code, notes, and snippets.

@minimal
Created January 19, 2013 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minimal/4575654 to your computer and use it in GitHub Desktop.
Save minimal/4575654 to your computer and use it in GitHub Desktop.
;; response to http://squirrel.pl/blog/2013/01/16/clojurescript-painkiller-for-oop/
(defn Bag []
(this-as this
(set! (.-store this) (array))
this))
(defprotocol MyBag
(add [this val])
(print [this]))
(extend-type Bag
MyBag
(add [this val]
(.push (.-store this) val))
(print [this]
(.log js/console (.-store this))))
(def mybag (Bag.))
(add mybag 2)
(add mybag 3)
(print mybag)
;;> [2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment