Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
protocol implementation in cljs
;; dummy protocol
(defprotocol IFoo
(foo [this]))
;; dummy cljs type
(deftype Bar [])
;; extending a cljs type
(extend-type Bar
IFoo (foo [this] (println "Hello from IFoo.foo for Bar")))
;; extending a js type
(extend-type js/Function
IFoo (foo [this] (println "Hello from IFoo.foo for js/Function")))
;; extending a js base type
(extend-type number
IFoo (foo [this] (println "Hello from IFoo.foo for number")))
//// cljs.user=> (extend-type Bar IFoo (foo [this] (println "Hello from IFoo.foo for Bar")))
(function() {
cljs.user.Bar.prototype.cljs$user$IFoo$ = true;
return cljs.user.Bar.prototype.cljs$user$IFoo$foo$arity$1 = (function(this$) {
var this$__$1 = this;
return cljs.core.println.call(null, "Hello from IFoo.foo for Bar");
});
})()
//// cljs.user=> (extend-type js/Function IFoo (foo [this] (println "Hello from IFoo.foo for js/Function")))
(function() {
Function.prototype.cljs$user$IFoo$ = true;
return Function.prototype.cljs$user$IFoo$foo$arity$1 = (function(this$) {
var this$__$1 = this;
return cljs.core.println.call(null, "Hello from IFoo.foo of js/Function");
});
})()
//// cljs.user=> (extend-type number IFoo (foo [this] (println "Hello from IFoo.foo for number")))
(function() {
(cljs.user.IFoo["number"] = true);
return (cljs.user.foo["number"] = (function(this$) {
return cljs.core.println.call(null, "Hello from Foo.foo of number");
}));
})()

viebel commented Mar 23, 2016

Hey Shaun.
Now, with KLIPSE you can generate dynamic gists for clojurescript code.
Have a look here KLIPSE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment