URL: http://github.com/javascript-tutorial/fa.javascript.info/pull/93.patch
برای زمانی که نیاز داریم تا تنها برای یک متغیر خاص یا پارامترهای خاصی برای فانکشن توقف کنیم کارآمد باشد. ``` -## Debugger command +## دستور debugger -We can also pause the code by using the `debugger` command in it, like this: +ما همچنین میتوانیم با استفاده از دستور `debugger` کد را متوقف کنیم، مثلاً: ```js function hello(name) { let phrase = `Hello, ${name}!`; *!* - debugger; // <-- the debugger stops here + debugger; // <-- اشکالزدا اینجا توقف میکند */!* say(phrase); } ``` -That's very convenient when we are in a code editor and don't want to switch to the browser and look up the script in developer tools to set the breakpoint. +این امکان در زمانی که در یک ویرایشگر کد هستیم و نمیخواهیم به مرورگر برویم و اسکریپت را در developer tools پیدا کنیم و بریکپوینت را ست کنیم خیلی مناسب است. -## Pause and look around +## توقف و گَشتن -In our example, `hello()` is called during the page load, so the easiest way to activate the debugger (after we've set the breakpoints) is to reload the page. So let's press `key:F5` (Windows, Linux) or `key:Cmd+R` (Mac). +در مثال ما، `hello()` در زمان بارگزاری صفحه صدا زده میشه، پس سادهترین راه برای فعالکردن اشکالزدا (بعد از ست کردن بریکپوینت) بارگزاری مجدد صفحهست. پس بیاید `key:F5` (Windows, Linux) یا `key:Cmd+R` (Mac) رو فشار بدیم. -As the breakpoint is set, the execution pauses at the 4th line: +همانطور که بریکپوینت ست شده، اجرای کد در خط چهارم متوقف میشه:  -Please open the informational dropdowns to the right (labeled with arrows). They allow you to examine the current code state: +دراپداونهای سمت راست(مشخصشده با فلش) رو باز کنید. با استفاده از اونها میتونید وضعیت فعلی کد رو بررسی کنید: -1. **`Watch` -- shows current values for any expressions.** +1. **`Watch` -- .نمایش مقادیر فعلی برای هر عبارت** - You can click the plus `+` and input an expression. The debugger will show its value at any moment, automatically recalculating it in the process of execution. + شما میتونید دکمه بهعلاوه `+` رو فشار بدید و یک عبارت وارد کنید. اشکالزدا مقدار آن را در هر لحظه از فرآیند اجرا، به صورت خودکار دوباره محاسبه میکنه و نمایش خواهد داد. -2. **`Call Stack` -- shows the nested calls chain.** +2. **`Call Stack` -- .نمایش زنجیرهٔ صدازدنهای تودرتو** - At the current moment the debugger is inside `hello()` call, called by a script in `index.html` (no function there, so it's called "anonymous"). + در لحظهٔ فعلی اشکالزدا صدازدهشده توسط `hello()` است, که خود آن صدازدهشده توسط اسکریپتی با نام `index.html` است. (هیچ تابعی وجود ندارد، پس «anonymous» نامیده میشود). - If you click on a stack item (e.g. "anonymous"), the debugger jumps to the corresponding code, and all its variables can be examined as well. -3. **`Scope` -- current variables.** + اگر بر روی یک پشته کلیک کنید (مثلاً«anonymous»)، اشکالزدا به کد متناظر آن میپرد، و همهٔ متغیرهای آن میتوانند بررسی شوند. +3. **`Scope` -- متغیرهای فعلی** - `Local` shows local function variables. You can also see their values highlighted right over the source. + `Local` متغیرهای تابع محلی را نمایش میدهد. همچنین میتوانید مقادیر آنها را برجستهشده سمت راست منبع ببینید. - `Global` has global variables (out of any functions). + `Global` شامل متغیرهای سراسری میشود. (بیرون از توابع). - There's also `this` keyword there that we didn't study yet, but we'll do that soon. + همچنین کلیدواژهٔ `this` نیز در آنجا وجود دارد که ما هنوز یاد نگرفتهایم، ولی بهزودی خواهیم گرفت. -## Tracing the execution +## ردیابی فرآیند اجرا -Now it's time to *trace* the script. +اکنون وقت آن است که اسکریپت را *ردیابی* کنیم. -There are buttons for it at the top of the right panel. Let's engage them. +دکمههایی برای اینکار در بالای پنل سمت راست وجود دارد. بیاید از آنها استفاده کنیم. - -- "Resume": continue the execution, hotkey `key:F8`. -: Resumes the execution. If there are no additional breakpoints, then the execution just continues and the debugger loses control. + -- "Resume": فرآیند اجرا را ادامه میدهد، میانبر `key:F8`. +:فرآیند اجرا را ادامه میدهد. اگر هیچ بریکپوینت دیگری نبود، تنها فرآیند اجرا ادامه پیدا میکند و اشکالزدا کنترل را از دست میدهد. - Here's what we can see after a click on it: + بعد از کلیک روی آن، چنین چیزی را میبینیم:  - The execution has resumed, reached another breakpoint inside `say()` and paused there. Take a look at the "Call Stack" at the right. It has increased by one more call. We're inside `say()` now. + فرآیند اجرا ادامه پیدا کردهست، به بریکپوینت دیگری درون `say()` رسیده است و متوقف شده است. به «Call Stack» در سمت راست نگاه کنید. با یک صدازدن دیگر افزایش پیداکرده است. ما هماکنون درون `say()` هستیم. - -- "Step": run the next command, hotkey `key:F9`. -: Run the next statement. If we click it now, `alert` will be shown. + -- "Step": دستور بعدی را اجرا میکند, میانبر `key:F9`. +: عبارت بعدی را اجرا میکند. اگر آن را کلیک کنیم، `alert` نمایش داده خواهد شد. - Clicking this again and again will step through all script statements one by one. + کلیک کردن دوباره و دوباره این، گامبهگام همهٔ عبارات اسکریپت را اجرا میکند. - -- "Step over": run the next command, but *don't go into a function*, hotkey `key:F10`. -: Similar to the previous "Step" command, but behaves differently if the next statement is a function call. That is: not a built-in, like `alert`, but a function of our own. + -- "Step over": دستور بعدی را اجرا میکند، اما *داخل یک تابع نمیشود*، میانبر `key:F10`. +: شبیه دستور قبلی «step»، اما اگر عبارت بعدی یک تابع - که built-in نباشد، مانند `alert` باشد، بلکه یک تابع که خودمان آن را تعریف کرده باشیم - باشد، متقاوت رفتار میکند. - The "Step" command goes into it and pauses the execution at its first line, while "Step over" executes the nested function call invisibly, skipping the function internals. + دستور «step» وارد آن میشود و فرآیند اجرا را در خطر اول آن متوقف میکند، در حالی که دستور «step over» صدازدنهای تودرتو تابع را نامرئی اجرا میکند، از تابعهای داخلی رد میشود. - The execution is then paused immediately after that function. + سپس فرآیند اجرا بعد از آن تابع بلافاصله متوقف میشود. - That's good if we're not interested to see what happens inside the function call. + این دستور اگر نخواهیم ببینیم داخل تابع چه اتفاقی میافتد، میتواند مفید واقع شود. - -- "Step into", hotkey `key:F11`. -: That's similar to "Step", but behaves differently in case of asynchronous function calls. If you're only starting to learn JavaScript, then you can ignore the difference, as we don't have asynchronous calls yet. + -- "Step into", میانبر `key:F11`. +: شبیه «step», اما در صورتی که تابع ناهمگام باشد، متقاوت رفتار میکند. اگر تازه شروع به یادگیری جاوااسکریپت کرده اید، میتوانید این تفاوت را نادیده بگیرید، چون هنوز توابع ناهمگام را نمیدانیم. - For the future, just note that "Step" command ignores async actions, such as `setTimeout` (scheduled function call), that execute later. The "Step into" goes into their code, waiting for them if necessary. See [DevTools manual](https://developers.google.com/web/updates/2018/01/devtools#async) for more details. + برای آینده، به خاطر داشته باشید که دستور «Step» command عملهای ناهمگام را نادیده میگیرد، مانند `setTimeout` (زمانبندی صدازدن توابع), که بعداً اجرا میکند. دستور «Step into» وارد آنها میشود، اگر نیاز باشد برای آنها صبر میکند. [DevTools manual](https://developers.google.com/web/updates/2018/01/devtools#async) را برای اطلاعات بیشتر ببینید. - -- "Step out": continue the execution till the end of the current function, hotkey `key:Shift+F11`. -: Continue the execution and stop it at the very last line of the current function. That's handy when we accidentally entered a nested call using , but it does not interest us, and we want to continue to its end as soon as possible. + -- "Step out": فرآیند اجرا را تا انتهای تابع فعلی ادامه میدهد, میانبر `key:Shift+F11`. +: فرآیند اجرا را ادامه میدهد و در خط آخر تابع فعلی متوقف میشود. در زمانی که تصادفاً وارد یک تابع تودرتو شدهایم ولی علاقهای به، آن نداریم، و میخواهیم در سریعترین زمان ممکن به آخر آن برسیم، کاربردی است. -- enable/disable all breakpoints. -: That button does not move the execution. Just a mass on/off for breakpoints. +: این دکمه فرآیند اجرا را تغییر نمیده. فقط برای خاموش/روشن کردن بریکپوینها به صورت کلیست. -- enable/disable automatic pause in case of an error. -: When enabled, and the developer tools is open, a script error automatically pauses the execution. Then we can analyze variables to see what went wrong. So if our script dies with an error, we can open debugger, enable this option and reload the page to see where it dies and what's the context at that moment. +: زمانی که فعال باشد، و Developer tools باز باشد، در زمان وقوع خطا اسکریپت به صورت خودکار متوقف میشود. بعد از آن میتوانیم متغیرها را تحلیل کنیم تا مشکل را پیدا کنیم. پس اگر اسکریپت ما با یک خطا از کار افتاد، میتوانیم اشکالزدا را باز کنیم، این امکان را فعال کنیم و صفحه را مجدداً بارگزاری کنیم تا ببینیم مشکل در کجا بوده است و نوشته در آن لحظه چه بوده است. ```smart header="Continue to here" -Right click on a line of code opens the context menu with a great option called "Continue to here". +راست کلیک برروی یک خط کد context menu را باز میکند همراه با امکانی عالی که «Continue to here» نامیده میشود. -That's handy when we want to move multiple steps forward to the line, but we're too lazy to set a breakpoint. +هنگامی که میخواهیم چندین گام به جلو برویم، ولی خیلی تنبل هستیم تا یک بریکپوینت ست کنیم، کاربردی است. ``` -## Logging +## رخدادنگاری -To output something to console from our code, there's `console.log` function. +برای برونداد چیزی به کنسول از کدمان، میتوان از تابع `console.log` استفاده کرد. -For instance, this outputs values from `0` to `4` to console: +برای مقال، این مقادیر `0` تا `4` را به کنسول برونداد میکند: ```js run -// open console to see +// کنسول را باز کنید تا ببینید for (let i = 0; i < 5; i++) { console.log("value,", i); } ``` -Regular users don't see that output, it is in the console. To see it, either open the Console panel of developer tools or press `key:Esc` while in another panel: that opens the console at the bottom. +کاربران معمولی آن را نمیبینند، چون در کنسول است. برای دیدن آن، یا پنل کنسول را در developer tools باز کنید و یا دکمه `key:Esc` را هنگامی که در یک پنل دیگر هستید بفشارید، کنسول در پایین صفحه باز میشود. -If we have enough logging in our code, then we can see what's going on from the records, without the debugger. +اگر به میزان کافی رخدادنگاری در کد داشته باشیم، میتوانیم از سوابق ببینیم چه اتفاقی افتاده است، بدون نیاز به اشکالزدا. -## Summary +## خلاصه -As we can see, there are three main ways to pause a script: -1. A breakpoint. -2. The `debugger` statements. -3. An error (if dev tools are open and the button is "on"). +همانطور که میبینیم، سه راه اصلی برای متوقف کردن یک اسکریپت وجود دارد: +1. یک بریکپوینت. +2. عبارات `debugger`. +3. یک خطا (اگر dev tools باز باشد و دکمه «on» باشد). -When paused, we can debug - examine variables and trace the code to see where the execution goes wrong. +وقتی متوقف شد، میتوانیم اشکالزدایی کنیم - بررسی توابع و ردیابی کد تا ببینیم کجای فرآیند اجرا به مشکل خورده است. -There are many more options in developer tools than covered here. The full manual is atNote: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: