In JavaScript, the `this` identifier gets "bound" when a function is
called. Determining what to bind is from either:
* Looking up the object that the function was called from
* An explicit parameter in these functions:
* `Function.prototype.apply`
* `Function.prototype.call`
So the following two lines are identical:
field.getEditableIframe();
field.getEditableIframe.call(field);
Problem is that ClojureScript does something special. Function calls
always bind `null`.
For example, a call in ClojureScript:
(def iframe ((.getEditableIframe field)))
Emits something like this:
iframe = field.getEditableIframe.call(null);
This problem is breaking quite a few things in Google Closure. In the
above example, Field.prototype.getEditableIframe relies on `this`
being bound properly.
My current work around is:
(defn call [o f] (js* "~{f}.call(~{o})"))
(def iframe (call field (.getEditableIframe field)))
Which generates something like:
iframe = field.getEditableIframe(field);
Obviously emitting raw JavaScript is less than ideal. Am I missing
something built-in to ClojureScript or are there any ideas for a
better work around?
Thanks,
Brian McKenna
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en