4

In clojurescript 1.9.89 and Chrome 50.0.2661.102, I can create a log statement like:

(js/console.log "works")

But I can't create one like:

(def brokenlog js/console.log)
(brokenlog "but not here")

--> #object[TypeError TypeError: Illegal invocation]

When I try to compare these approaches by printing the value of my own brokenlog function, it looks just like the "real one" -- that is, both brokenlog and js/console.log evaluate for me as:

#object[log "function log() { [native code] }"]

Similarly, I see this behavior with:

cljs.user=> (js/document.querySelector "body")
#object[HTMLBodyElement [object HTMLBodyElement]]
cljs.user=> (def l js/document.querySelector)
#'cljs.user/l
cljs.user=> (l "body")
#object[TypeError TypeError: Illegal invocation]
nil

Upgrading to Chrome 52 fixes the console.log behavior, but not the document.querySelector behavior.

So I have two questions:

1. What am I missing

2. Where are the official docs I should be reading that would explain it?

Thanks!

Bosh
  • 8,138
  • 11
  • 51
  • 77

1 Answers1

2

Which browser and clojurescript version you are using? the following code should work on your browser if it display nil into box.

.as-console-wrapper .as-console {
  display: none;
}
<pre><code class="language-klipse">
(js/console.log "Work!")
(def brokenlog js/console.log)
(brokenlog "Work again!")
; two line should be seen in your browser log
</code></pre>
<script>
    window.klipse_settings = {
        selector: '.language-klipse', // css selector for the html elements you want to klipsify
    };
</script>
<script src="http://app.klipse.tech/plugin/js/klipse_plugin.js?"></script>
<link href="http://app.klipse.tech/css/codemirror.css" rel="stylesheet"/>

EDIT

Here is the clojurescript

(ns hello-world.core)
(def mylog js/console.log)
(mylog "Hello")

compiled to javascript

hello_world.core.mylog = console.log;
hello_world.core.mylog.call(null,"Hello");

console.log.call(null, ....) trigger the chrome bug, console.log expecting this is the console object. It should be fixed as mentioned in the issue log https://bugs.chromium.org/p/chromium/issues/detail?id=167911.

ka yu Lai
  • 571
  • 3
  • 13
  • I've updated my question to specify versions -- the issue is with clojurescript 1.9.89 and Chrome 50.0.2661.102, – Bosh Aug 15 '16 at 04:01
  • It should be a chrome specific bug which fixed at about Apr 2016. https://bugs.chromium.org/p/chromium/issues/detail?id=167911 – ka yu Lai Aug 15 '16 at 04:57
  • This same behavior and error occurrs with any js function I try (e.g. document.querySelector) -- so I don't think the console.log bug explains it. – Bosh Aug 15 '16 at 11:33
  • Ah, the compiled code explains this very clearly -- thanks! – Bosh Aug 15 '16 at 11:42