Last active
June 18, 2016 16:37
-
-
Save shaunlebron/a98a05b47a1521b58a6b to your computer and use it in GitHub Desktop.
protocol implementation in cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// 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"); | |
})); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Shaun.
Now, with KLIPSE you can generate dynamic gists for clojurescript code.
Have a look here KLIPSE