Skip to content

Instantly share code, notes, and snippets.

@antoineB
Created November 20, 2012 14:18
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 antoineB/2830a82227d881a9d90a to your computer and use it in GitHub Desktop.
Save antoineB/2830a82227d881a9d90a to your computer and use it in GitHub Desktop.
(defmacro goog-extend [type base-type ctor & methods]
`(do
(defn ~type ~@ctor)
(goog/inherits ~type ~base-type)
~@(map
(fn [method]
`(if (= \- (first (str (first method))))
(set! (.. ~type -protitype ~(first method)) (second method))
(set! (.. ~type -prototype ~(to-property (first method)))
(fn ~@(rest method))))
methods)))
;; and use like
(ns move.views
(:require [goog.ui.tree.TreeControl :as TreeControl])
(:use-macros [move.macros :only [goog-extend]]
[cljs.core :only [this-as]]))
(goog-extend
MyTree goog/ui.tree.TreeControl
([name config]
(this-as this
(goog/base this name config)))
(-notAfunction 12)
(handleKeyEvent
[e]
(this-as this
(goog/base this "handleKeyEvent" e)
;; my special code to handle the key event
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment