OK, unless there's some way to set arbitrary properties on a Java object, I
guess this isn't possible...
ClojureScript:cljs.user> (aset js/Packages.clojure.lang.IFn "prototype"
(js/Object.))
"Error evaluating:" (aset js/Packages.clojure.lang.IFn "prototype"
(js/Object.)) :as "(Packages.clojure.lang.IFn[\"prototype\"] = (new
Object()));\n"
org.mozilla.javascript.EvaluatorException: Java class "clojure.lang.IFn"
has no public instance field or method named "prototype". (<cljs repl>#9)
at <cljs repl>:9 (anonymous)
at <cljs repl>:9
On 31 December 2012 09:41, Stuart Campbell <[email protected]> wrote:
> Ah, you're right -- thanks. That leads me to another error:
>
> ClojureScript:cljs.user> (extend-type js/Packages.clojure.lang.IFn IFn
> (-invoke ([this] (.invoke this))))
> "Error evaluating:" (extend-type js/Packages.clojure.lang.IFn IFn (-invoke
> ([this] (.invoke this)))) :as
> "Packages.clojure.lang.IFn.prototype.cljs$core$IFn$ =
> true;\nPackages.clojure.lang.IFn.prototype.call = (function
> (this_sym23394){\nvar this_sym23394__23395 = this;\nvar this__23396 =
> this_sym23394__23395;\nreturn
> this__23396.invoke();\n});\nPackages.clojure.lang.IFn.prototype.apply =
> (function (this_sym23392,args23393){\nreturn
> this_sym23392.call.apply(this_sym23392,[this_sym23392].concat(args23393.slice()));\n});\n"
> org.mozilla.javascript.EcmaError: TypeError: Cannot set property
> "cljs$core$IFn$" of null to "true" (<cljs repl>#25)
> at <cljs repl>:25 (anonymous)
> at <cljs repl>:25 (anonymous)
> at <cljs repl>:25
>
> I'll keep investigating.
>
> On 30 December 2012 12:31, David Nolen <[email protected]> wrote:
>
>> I think you've just formatted your code incorrectly. Did you try
>> something like this?
>>
>> (extend-type js/Packages.clojure.lang.IFn
>> IFn
>> (-invoke
>> ([this] (.invoke this))
>> ([this a] (.invoke this a)))
>> )
>>
>>
>> On Sat, Dec 29, 2012 at 8:22 PM, Stuart Campbell <[email protected]>wrote:
>>
>>> Hi all,
>>>
>>> I'm toying with a way to use Clojure objects from a Rhino-based
>>> ClojureScript environment (https://github.com/harto/rhino-bridge).
>>>
>>> I've been able to export a Clojure function into the ClojureScript
>>> environment without too much difficulty. Ideally, I'd like to be able to
>>> call that function as if it were a regular ClojureScript function.
>>>
>>> I was hoping I could do something like:
>>>
>>> (extend-type js/Packages.clojure.lang.IFn
>>> IFn
>>> (-invoke [this] (.invoke this))
>>> (-invoke [this a] (.invoke this a))
>>> ;; etc
>>> )
>>>
>>> However, this yields an error that I don't quite understand:
>>>
>>> java.lang.UnsupportedOperationException: nth not supported on this type:
>>> Symbol
>>> at clojure.lang.RT.nthFrom(RT.java:846)
>>> at clojure.lang.RT.nth(RT.java:796)
>>> at
>>> cljs.core$extend_type$assign_impls__7365$fn__7377$adapt_params__7380.invoke(core.clj:486)
>>> at clojure.core$map$fn__4087.invoke(core.clj:2434)
>>>
>>> In fact, I'm not sure this will work at all, since (type) doesn't appear
>>> to work with non-native JS objects.
>>>
>>> Is the extend-type method feasible?
>>>
>>> Cheers,
>>> Stuart
>>>
>>> --
>>> 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
>>
>>
>> --
>> 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
>
>
>
--
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