Chouser,

Yes, that does it---I didn't even think about my use of (apply js/f
args), thanks!

Is there a way to use the interop form with variable-arity JavaScript
functions without using `apply`?
This issue came up with my ClojureScript wrapper for D3; I'm using
this macro

    (defmacro shim [name]
      "Define a proxy to native D3 method"
      `(defn ~name [sel# & args#]
         (apply (. sel# ~name) args#)))

to define proxy functions.
If I can't use `apply` because of the `this = null` problem, do I have
to write out a case for each arity?

thanks,
kevin

On Aug 29, 6:24 am, Chouser <chou...@gmail.com> wrote:
> On Sun, Aug 28, 2011 at 9:22 PM, Kevin Lynagh <klyn...@gmail.com> wrote:
> > I am having trouble using ClojureScript to call JavaScript functions
> > that exploit prototype injection.
> > If I'm reading `defmethod :emit invoke` correctly,
>
> >    https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/com...
>
> > ClojureScript always seems to compile f(x) JavaScript calls as
>
> >    f.call(null, x)
>
> > which trip up any functions that rely on `this` to have certain
> > properties.
> > I have two questions:
>
> > 1) why are function calls compiled to the `f.call(null, ...)` form
> > rather than just `f(...)`? Is it to support the Closure Compiler?
>
> > 2) What is the appropriate way to use JavaScript functions that rely
> > on `this`?
> > Is there some way to emit `f.call(f, ...)`, or do I need to use `(js*
> > "f(...)")`?
>
> > For reference, here is a minimal JavaScript example of the JavaScript
> > prototype injection pattern:
>
> >    var p_injection = function(){};
> >    p_injection.one = function(){ return 1; };
>
> >    var MyClass = function(){};
>
> >    var x = new MyClass();
> >    x.two = function(){  return this.one() + 1; };
> >    x.__proto__ = p_injection;
> >    x.two(); // 2
> >    x.two.call(null); // error, object has no method "one()"
>
> Have you tried calling the method using the interop form?
>
> (. x (two))
>
> --Chouser

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to