JavaScript 除錯小筆記


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Protocol relative URL
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>window.jQuery || document.write('</script><script src="static/javascript/jquery-1.6.4.min.js">\x3C/script>')</script>

#
console.time("name"); # 記錄時間
console.log(variable); # 除錯
console.dir(variable); # 除錯
console.timeEnd("name"); # 記錄時間

inspect(variable); # 跳到相應的 element

$0 當前選定的 element text
$$ 類似於 jQuery 的 $

monitorEvents( $$(selector) ) # 監視滑鼠/鍵盤的動作
monitorEvents( $$(selector), 'key' ) # 只監視鍵盤的 KEY 動作

copy(object) 複雜當前的輸出

# Firefox
cd( $$(iframe#id)[0].contentWindow ) # 切換 content 至指定 iframe 裡
cd(top) 最上的 iframe

參考: http://www.youtube.com/watch?v=4mf_yNLlgic