Imagine the task is to create some utility lib in clojurescript so it can be used from JS.
For example, let's say I want to produce an equivalent of:
var Foo = function(a, b, c){
this.a = a;
this.b = b;
this.c = c;
}
Foo.prototype.bar = function(x){
return this.a + this.b + this.c + x;
}
var x = new Foo(1,2,3);
x.bar(3); // >> 9
One way to achieve it I came with is:
(deftype Foo [a b c])
(set! (.bar (.prototype Foo))
(fn [x]
(this-as this
(+ (.a this) (.b this) (.c this) x))))
(def x (Foo. 1 2 3))
(.bar x 3) ; >> 9
Question: is there more elegant/idiomatic way of the above in clojurescript?