And, here’s how you use it. In this example, I’m extending
goog.ui.tree.TreeControl so that I can override handleKeyEvent and
provide a bit richer interaction with my tree.
12345678910111213141516
(ns move.views(:require[goog.ui.tree.TreeControl:asTreeControl])(:use-macros[move.macros:only[goog-extend]][cljs.core:only[this-as]]))(goog-extendMyTreegoog/ui.tree.TreeControl([name config](this-asthis(goog/basethisname config)))(handleKeyEvent[e](this-asthis(goog/basethis"handleKeyEvent"e);; my special code to handle the key event)))
When this is compiled, it expands to this javascript:
123456789101112
move.views.MyTree=functionMyTree(name,config){varthis__44428=this;returngoog.base(this__44428,name,config)};goog.inherits(move.views.MyTree,goog.ui.tree.TreeControl);move.views.MyTree.prototype.handleKeyEvent=function(e){varthis__44429=this;goog.base(this__44429,"handleKeyEvent",e);// my special code to handle the key event};
Cool! That’s pretty close to the code I need to write by hand when
extending google closure classes in my javascript code.
This code will work great if we compile with standard optimizations
but we get into trouble in advanced mode. The Closure compiler does
more error checking in advanced mode and wrongly flags our call to
goog.base for not having this as its first argument. That’s
unfortunate but not a big deal. We just have to write some less
idiomatic code to fix it:
1234567891011121314
(ns move.views(:require[goog.ui.tree.TreeControl:asTreeControl])(:use-macros[move.macros:only[goog-extend]][cljs.core:only[this-as]]))(goog-extendMyTreegoog/ui.tree.TreeControl([name config](goog/base(js*"this")name config))(handleKeyEvent[e](goog/base(js*"this")"handleKeyEvent"e);; my special code to handle the key event)))
This will generate the code that the advanced compiler is looking for.