我最近开始使用ClojureScript.当我将JavaScript程序重写为ClojureScript时,我担心ClojureScript的性能.
ClojureScript代码
(def NUM 10000)
(def data
(vec (repeatedly NUM #(hash-map :x (rand) :y (rand)))))
(.time js/console "cljs")
(loop [x 0 y 0 d data]
(if (empty? d)
[x y]
(recur (+ x (:x (first d)))
(+ y (:y (first d)))
(rest d))))
(.timeEnd js/console "cljs")
Run Code Online (Sandbox Code Playgroud)
编译的JavaScript代码(优化:空白)
benchmark_cljs.benchmark.NUM = 1E4;
benchmark_cljs.benchmark.data = cljs.core.vec.call(null, cljs.core.repeatedly.call(null, benchmark_cljs.benchmark.NUM, function() {
return cljs.core.PersistentHashMap.fromArrays.call(null, [new cljs.core.Keyword(null, "x", "x", 1013904362), new cljs.core.Keyword(null , "y", "y", 1013904363)], [cljs.core.rand.call(null), cljs.core.rand.call(null)]);
}));
console.time("cljs");
var x_4753 = 0;
var y_4754 …Run Code Online (Sandbox Code Playgroud) 我正在使用<webview>标签嵌入页面。<webview>标签有shadow-root一个标签,<object id="browser-plugin-1 ...>。所以我试着scrollTop像这样设置这个标签的值。
var webView = document.getElementById('webview tag id');
var elm = webView.shadowRoot.firstChild; // elm is object tag
console.log(elm.scrollTop); // 0
elm.scrollTop = 100;
console.log(elm.scrollTop); // 0
Run Code Online (Sandbox Code Playgroud)
但是什么也没发生......
是否可以<webview>从外部控制标签滚动位置?
当我运行以下简单程序时,打印"信息后"消息后需要一分钟直到完成.
$ lein run -m logger.core
(ns logger.core
(:require [taoensso.timbre :as timbre]))
(defn -main []
(println "before info")
(timbre/info "hello world")
(println "after info"))
Run Code Online (Sandbox Code Playgroud)
如果我发表评论(timbre/info "hello world"),那浪费时间就完全消失了.
是什么原因?我怎样才能避免这种情况呢?
提前致谢.