Why do js functions fail when I assign them to a local variable?

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

(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 typing the value of my own function brokenlog, it looks just like "real", i.e. both brokenlog, and js/console.logevaluate 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 behavior console.log, but not behavior document.querySelector.

I have two questions:

1. What I miss

2. Where should I read white papers that could explain this?

Thank!

+4
source share
1 answer

clojurescript ? , .

.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"/>

clojurescript

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

javascript

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

console.log.call(null,....) -, console.log , this console. , https://bugs.chromium.org/p/chromium/issues/detail?id=167911.

+2

Source: https://habr.com/ru/post/1651165/


All Articles