ホームページ >ウェブフロントエンド >jsチュートリアル >VS Code&Chrome Debuggerを使用したJavaScriptプロジェクトのデバッグ
VSコードとChromeデバッガーを使用したマスターJavaScriptデバッグ:包括的なガイド
JavaScriptデバッグに依存することにうんざりしていませんか?この記事では、Visual Studioコード(VSコード)とChromeデバッガー拡張機能を使用して、デバッグワークフローを変換する強力なデバッグ手法を紹介します。
console.log()
のない世界を想像してください。 デバッグは悪夢です! は簡単な修正を提供しますが、複雑な問題には面倒になります。 デバッグツールは、優れた代替品を提供します。 このガイドは、vs Codeの統合デバッガーとChrome Devtoolsとのシームレスな統合のためにChrome拡張機能のデバッガーを利用しています。
重要な利点:console.log()
console.log()
合理化されたデバッグ、信頼を排除します。 特定のポイントで実行を一時停止するための正確なブレークポイント。
console.log()
カスタマイズ可能なlaunch.json
node.js Visual Studioコード
debug-example
リポジトリをクローンします。
debug-example
vsコードでプロジェクトを開きます。
debug-example
<code class="language-bash">npm install npm install -g mocha</code>
ブレークポイントの設定:
ライン番号の横にある溝をクリックして、ブレークポイント(赤い点)を設定します。
src/places.js
<code class="language-javascript">const places = []; module.exports = { places, addPlace: (city, country) => { const id = ++places.length; // Bug: Modifies places.length prematurely let numType = 'odd'; if (id % 2) { // Bug: Incorrect modulus condition numType = 'even'; } places.push({ id, city, country, numType }); }, }; module.exports.addPlace('Mombasa', 'Kenya'); module.exports.addPlace('Kingston', 'Jamaica'); module.exports.addPlace('Cape Town', 'South Africa');</code>
launch.json
:ギアアイコンをクリックしてlaunch.json
を作成します。 デバッグするように構成places.js
:<code class="language-bash">npm install npm install -g mocha</code>
デバッグコントロール:デバッグツールバーコントロールを使用:続行、ステップオーバー、ステップアウト、再起動、停止。
変数を越えて値を確認するか、デバッグパネルの「変数」と「監視」セクションを使用します。
(未熟な長さの増分と誤った弾性条件)を特定します。それに応じてコードを修正します。
places.js
モカ構成の追加:
デバッグを開始します:placesTest.js
「Mochaテスト」を選択し、デバッグを開始します。 テスト、変数を検査して、残りの問題を識別および修正します。 フックを追加して、テスト間で
Chromeデバッガーを使用したクライアント側コードのデバッグ:beforeEach
places
launch.json
Express Server(<code class="language-javascript">const places = []; module.exports = { places, addPlace: (city, country) => { const id = ++places.length; // Bug: Modifies places.length prematurely let numType = 'odd'; if (id % 2) { // Bug: Incorrect modulus condition numType = 'even'; } places.push({ id, city, country, numType }); }, }; module.exports.addPlace('Mombasa', 'Kenya'); module.exports.addPlace('Kingston', 'Jamaica'); module.exports.addPlace('Cape Town', 'South Africa');</code>デバッグを開始します:
クライアントサイドコードのデバッグ:npm start
クライアント側のjavascript(
概要:
、拥抱高效调试! console.log()
以上がVS Code&Chrome Debuggerを使用したJavaScriptプロジェクトのデバッグの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。