Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
測試與除錯
|
157
通常建議採用第二種做法(相信你也不希望冒險在正式環境的程式碼裡,安插
debugger
敘述句吧!)當 JavaScript 程式執行到中斷點的位置,會暫停執行,讓你有機會好好檢
查一下目前的作用域(scope),如圖 9-11 所示。
9-11 在 Safari 的網頁檢查工具裡,利用中斷點進行除錯
在「Script」頁籤的右邊,可以看到完整的呼叫堆疊、區域 / 全域變數,以及其他和除錯
相關的資訊。如果你把滑鼠游標移到任一變數上面,還可以看到目前的變數值。這時如
果切換至「Console」頁籤,它的執行環境會和目前的中斷點一致,你可以在主控台裡對
變數進行各種處理,或是呼叫其他的函式。
遇到中斷點後,你可以選擇要繼續逐行執行程式碼、跳入 / 跳出某個函式呼叫,也可以
利用右方的除錯工具列,隨時掌握目前堆疊資訊的變化。每種瀏覽器的除錯工具列圖示
可能都不盡相同,不過如果你把滑鼠游標移到工具列圖示上面,就會出現一組黃色的說
明方框,裡面會說明這個工具列圖示的功能為何。
千萬別忘了,每次重新載入網頁時,程式都會在中斷點的位置暫停。如果想要移除中斷
點,就要再點擊一次中斷點所在的程式碼行號,或是在中斷點清單裡面取消選取該中斷
點。JavaScript 的除錯工具,可說是
console.log()
的絕佳替代方案,它可以讓你對於
程式的來龍去脈瞭若指掌。
分析網路請求
在網頁檢查工具的「Network」頁籤裡,會顯示目前網頁所發送的所有 HTTP 請求內容、
花費時間,以及完成時間。如圖 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811