Created
September 13, 2011 18:08
-
-
Save swannodette/1214547 to your computer and use it in GitHub Desktop.
closure_and_proto.clj
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
/* | |
Silly example - close over s (say a string) returning an instance | |
of an anonymous type that acts like a ClojureScript collection | |
(defn make-conjable [s] | |
(reify | |
ICollection | |
(-conj [_ c] (str s c)))) | |
*/ | |
function make_conjable(s) { | |
// check if the anonymous type is already memoized | |
if (cljs.core.truth_(cljs.core.undefined_QMARK_.call(null, cljs.user.t4240))) { | |
// define type | |
cljs.user.t4240 = (function (s, make_conjable) { | |
this.s = s; | |
this.make_conjable = make_conjable; | |
}); | |
cljs.user.t4240.prototype.cljs$core$ICollection$ = true; | |
cljs.user.t4240.prototype.cljs$core$ICollection$_conj = (function (_, c) { | |
var this__4241 = this; | |
return cljs.core.str.call(null, this__4241.s, c); | |
}); | |
} else { | |
} | |
// instantiate w/ closed over locals | |
return (new cljs.user.t4240(s, make_conjable)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment