刚开始跟 MDN 教程学 JavaScript,目前的方法是新建一个 HTML 文件,用 Chrome 打开来测试:
<!-- array-join.html -->
<script>
function assert(a, b) {
if (a !== b) {
alert(`${a} !== ${b}`);
}
}
const letters = ["a", "b", "c"];
assert("a,b,c", letters.join());
assert("a, b, c", letters.join(", "));
console.log("hello");
</script>
每次都需要先切回 Chrome 刷新,网上搜了个 AppleScript 自动刷新 Chrome 标签页,封装成 Emacs 命令,方便测试代码:
(defun chunyang-chrome-reload-tab ()
"Reload the active tab in Chrome."
(interactive)
(do-applescript
;; http://blog.viktorkelemen.com/2012/05/reload-active-tab-in-chrome-with.html
"tell application \"Google Chrome\" to reload active tab of window 0"))
(define-key js-mode-map (kbd "C-c C-c") #'chunyang-chrome-reload-tab)