> I am trying to write a CLJS (0df1bc4d7b) function that finds out the
> current system time in milliseconds, equivalent of (System/
> currentTimeMillis) in Clojure:
>
> (ns foo)
>
> (defn now []
> ;; new Date().getTime()
> (.getTime (js/Date.)))
>
>
> This displays the following when displayed using JavaScript
> alert("Found " + foo.now()):
>
> Found function getTime() {
> [native code]
> }
>
>
> When I wrap into a function call
> (defn now []
> ;; new Date().getTime()
> ((.getTime (js/Date.))))
>
> I see the exception in Firebug: "Can't convert null to object" while
> executing the following code:
> return(new Date).getTime.call(null)
>
> What am I doing wrong?
.getTime is a method which takes no arguments. In JavaScript (and by
extension ClojureScript) instance methods are also properties.
So in your case, (.getTime (js/Date.)) actually returns the value of
the method (the native code) instead of calling it.
If you wish to call .getTime instead, you'll have to invoke it thusly
- (. (js/Date.) (getTime))
Also note that this problem has been fixed in a very recent commit
with the introduction of a new property lookup syntax -
http://dev.clojure.org/display/design/Unified+ClojureScript+and+Clojure+field+access+syntax
Hope this helps.
Regards,
BG
--
Baishampayan Ghose
b.ghose at gmail.com
--
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