FAQ

[Clojure] what is "js/" in clojurescript?

Rob
May 3, 2012 at 4:12 am
Hi,

Syntax like this doesn't work in normal Clojure, right?

js/document.body.style

It just did in a ClojureScript repl. Is there something magic about "js/"
? What is it?

thanks,
Rob

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
reply

Search Discussions

9 responses

  • Tamreen Khan at May 3, 2012 at 4:17 am
    A quick explanation is that functions/other javascript objects that
    otherwise exist in the global namespace (ie. document, console, window) are
    accessed through the js/ in Clojurescript. This is a JS-specific thing and
    therefore you don't find js/ in regular Clojure.

    However, doing the form (MyClass/MyStaticMethod arg1 arg2 ...) *does* exist
    in Clojure. It's a way of calling static Java methods or accessing static
    fields. See http://clojure.org/java_interop for more info.
    On Thu, May 3, 2012 at 12:12 AM, Rob wrote:

    Hi,

    Syntax like this doesn't work in normal Clojure, right?

    js/document.body.style

    It just did in a ClojureScript repl. Is there something magic about "js/"
    ? What is it?

    thanks,
    Rob

    --
    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+unsubscribe@googlegroups.com
    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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Rob at May 3, 2012 at 4:50 am

    On Thursday, May 3, 2012 12:17:03 AM UTC-4, Tamreen Khan (Scriptor) wrote:

    However, doing the form (MyClass/MyStaticMethod arg1 arg2 ...) *does*
    exist in Clojure. It's a way of calling static Java methods or accessing
    static fields. See http://clojure.org/java_interop for more info.
    Okay. It seems like normal Clojure the thing after the slash can't have
    more '.' characters in it, so I'm wondering if that's the extend of the
    difference. Maybe that difference is not on purpose.


    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • David Nolen at May 3, 2012 at 3:47 pm
    I would not rely on this behavior. Follow Clojure's property access
    conventions.

    David
    On Thursday, May 3, 2012, Rob wrote:

    Hi,

    Syntax like this doesn't work in normal Clojure, right?

    js/document.body.style

    It just did in a ClojureScript repl. Is there something magic about "js/"
    ? What is it?

    thanks,
    Rob

    --
    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+unsubscribe@googlegroups.com
    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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Devin Walters at May 3, 2012 at 8:17 pm
    Some additional information if you're interested:
    http://dev.clojure.org/jira/browse/CLJS-89
    http://dev.clojure.org/display/design/Unified+ClojureScript+and+Clojure+field+access+syntax

    '(Devin Walters)

    On Thursday, May 3, 2012 at 10:47 AM, David Nolen wrote:

    I would not rely on this behavior. Follow Clojure's property access conventions.

    David
    On Thursday, May 3, 2012, Rob wrote:
    Hi,

    Syntax like this doesn't work in normal Clojure, right?

    js/document.body.style

    It just did in a ClojureScript repl. Is there something magic about "js/" ? What is it?

    thanks,
    Rob

    --
    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+unsubscribe@googlegroups.com
    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 clojure@googlegroups.com (mailto: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+unsubscribe@googlegroups.com (mailto:clojure+unsubscribe@googlegroups.com)
    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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Peter Taoussanis at Jan 7, 2013 at 1:09 pm
    I would not rely on this behavior. Follow Clojure's property access
    conventions.

    Sorry to dig this up again - would just like to clarify:

    The idiomatic way of accessing something like `window.location.pathname`
    then would be (aget js/window "location" "pathname"), or nested .-
    accesses, correct? I know things with Cljs are developing quickly and
    I keep seeing the `js/window.location.pathname` form pop up (including in
    Clojurescript's samples/twitterbuzz/src/twitterbuzz/anneal.cljs), so just
    wanted to double check.

    Assuming the latter form is indeed incorrect, any chance of adding a
    compiler warning to start dissuading people from using it?

    Thanks!

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • David Nolen at Jan 7, 2013 at 1:39 pm
    Yes a warning would be great as well as fixing the examples.

    Ticket & patch welcome.
    On Monday, January 7, 2013, Peter Taoussanis wrote:

    I would not rely on this behavior. Follow Clojure's property access
    conventions.

    Sorry to dig this up again - would just like to clarify:

    The idiomatic way of accessing something like `window.location.pathname`
    then would be (aget js/window "location" "pathname"), or nested .-
    accesses, correct? I know things with Cljs are developing quickly and
    I keep seeing the `js/window.location.pathname` form pop up (including in
    Clojurescript's samples/twitterbuzz/src/twitterbuzz/anneal.cljs), so just
    wanted to double check.

    Assuming the latter form is indeed incorrect, any chance of adding a
    compiler warning to start dissuading people from using it?

    Thanks!

    --
    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<javascript:_e({}, 'cvml', '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+unsubscribe@googlegroups.com <javascript:_e({}, 'cvml',
    'clojure%2bunsubscribe@googlegroups.com');>
    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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Peter Taoussanis at Jan 7, 2013 at 1:58 pm
    Thanks David.

    Ticket & patch welcome.
    >

    I've been lazy / holding out for the electronic CA, but I'll make a note to
    come back to this if no one else steps up.

    Cheers!

    >

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Jonas at Jan 12, 2013 at 12:35 pm
    Hi

    I created an issue+patch on
    JIRA: http://dev.clojure.org/jira/browse/CLJS-455

    Jonas
    On Monday, January 7, 2013 3:58:25 PM UTC+2, Peter Taoussanis wrote:

    Thanks David.

    Ticket & patch welcome.
    I've been lazy / holding out for the electronic CA, but I'll make a note
    to come back to this if no one else steps up.

    Cheers!
    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • David Nolen at Jan 12, 2013 at 4:02 pm
    Thanks!
    On Saturday, January 12, 2013, Jonas wrote:

    Hi

    I created an issue+patch on JIRA:
    http://dev.clojure.org/jira/browse/CLJS-455

    Jonas
    On Monday, January 7, 2013 3:58:25 PM UTC+2, Peter Taoussanis wrote:

    Thanks David.

    Ticket & patch welcome.
    I've been lazy / holding out for the electronic CA, but I'll make a note
    to come back to this if no one else steps up.

    Cheers!
    --
    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<javascript:_e({}, 'cvml', '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+unsubscribe@googlegroups.com <javascript:_e({}, 'cvml',
    'clojure%2bunsubscribe@googlegroups.com');>
    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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post