You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/08-settimeout-setinterval/article.md
+18-18
Original file line number
Diff line number
Diff line change
@@ -235,53 +235,53 @@ Pentru `setInterval`, funcția rămâne în memorie până când este apelată `
235
235
Există un efect secundar. O funcție face referire la mediul lexical extern, astfel încât, în timp ce ea trăiește, trăiesc și variabilele externe. Acestea pot ocupa mult mai multă memorie decât funcția însăși. Deci atunci când nu mai avem nevoie de funcția programată, este mai bine să o anulăm, chiar dacă este foarte mică.
236
236
````
237
237
238
-
## Zero delay setTimeout
238
+
## setTimeout cu Întârziere zero
239
239
240
-
There's a special use case: `setTimeout(func, 0)`, or just`setTimeout(func)`.
240
+
Există un caz special de utilizare: `setTimeout(func, 0)`, sau doar`setTimeout(func)`.
241
241
242
-
This schedules the execution of`func`as soon as possible. But the scheduler will invoke it only after the currently executing script is complete.
242
+
Acest lucru planifică execuția lui`func`cât mai curând posibil. Dar planificatorul îl va invoca numai după ce scriptul în curs de execuție este finalizat.
243
243
244
-
So the function is scheduled to run "right after" the current script.
244
+
Astfel funcția este planifică să se execute "imediat după" scriptul curent.
245
245
246
-
For instance, this outputs "Hello", then immediately "World":
246
+
De exemplu, aceasta produce "Hello", apoi imediat "World":
247
247
248
248
```js run
249
249
setTimeout(() =>alert("World"));
250
250
251
251
alert("Hello");
252
252
```
253
253
254
-
The first line "puts the call into calendar after 0ms". But the scheduler will only "check the calendar" after the current script is complete, so `"Hello"`is first, and`"World"` -- after it.
254
+
Prima linie "pune apelul în calendar după 0ms". Dar planificatorul va "verifica calendarul" numai după ce scriptul curent este finalizat, așa că `"Hello"`este primul, iar`"World"` -- după el.
255
255
256
-
There are also advanced browser-related use cases of zero-delay timeout, that we'll discuss in the chapter<info:event-loop>.
256
+
Există de asemenea cazuri avansate de utilizare a timeout-ului cu întârziere zero legate de browser, pe care le vom discuta în capitolul<info:event-loop>.
257
257
258
-
````smart header="Zero delay is in fact not zero (in a browser)"
259
-
In the browser, there's a limitation of how often nested timers can run. The [HTML Living Standard](https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers) says: "after five nested timers, the interval is forced to be at least 4 milliseconds.".
258
+
````smart header="Întârzierea zero nu este de fapt zero (într-un browser)"
259
+
În browser, este o limitare pentru cât de des pot rula temporizatoarele imbricate. [HTML Living Standard](https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers) spune: "după cinci temporizatoare imbricate, intervalul este forțat să fie de cel puțin 4 milisecunde.".
260
260
261
-
Let's demonstrate what it means with the example below. The `setTimeout` call in it re-schedules itself with zero delay. Each call remembers the real time from the previous one in the `times` array. What do the real delays look like? Let's see:
261
+
Să demonstrăm ce înseamnă acest lucru cu exemplul de mai jos. Apelul `setTimeout` cuprins în el se reprogramează singur cu întârziere zero. Fiecare apel reține întârzierea reală din cel precedent în matricea `times`. Cum arată întârzierile reale? Să vedem:
262
262
263
263
```js run
264
264
let start = Date.now();
265
265
let times = [];
266
266
267
267
setTimeout(function run() {
268
-
times.push(Date.now() - start); // remember delay from the previous call
268
+
times.push(Date.now() - start); // ține minte întârzierea de la apelul anterior
269
269
270
-
if (start + 100 < Date.now()) alert(times); // show the delays after 100ms
271
-
else setTimeout(run); // else re-schedule
270
+
if (start + 100 < Date.now()) alert(times); // arată întârzierile după 100ms
First timers run immediately (just as written in the spec), and then we see `9, 15, 20, 24...`. The 4+ ms obligatory delay between invocations comes into play.
278
+
Primele temporizatoare se execută imediat (așa cum este scris în specificație), iar apoi vedem `9, 15, 20, 24...`. Intră în joc întârzierea obligatorie de 4+ ms între invocări.
279
279
280
-
The similar thing happens if we use `setInterval` instead of `setTimeout`: `setInterval(f)` runs `f` few times with zero-delay, and afterwards with 4+ ms delay.
280
+
Un lucru similar se întâmplă dacă folosim `setInterval` în loc de `setTimeout`: `setInterval(f)` rulează `f` de câteva ori cu întârziere zero, iar apoi cu întârziere de 4+ ms.
281
281
282
-
That limitation comes from ancient times and many scripts rely on it, so it exists for historical reasons.
282
+
Această limitare provine din timpuri străvechi și multe scripturi se bazează pe ea, așa că există din motive istorice.
283
283
284
-
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [setImmediate](https://nodejs.org/api/timers.html#timers_setimmediate_callback_args) for Node.js. So this note is browser-specific.
284
+
Pentru JavaScript pe server, această limitare nu există și există alte modalități de a programa o sarcină asincronă imediată, cum ar fi [setImmediate](https://nodejs.org/api/timers.html#timers_setimmediate_callback_args) pentru Node.js. Deci această notă este specifică browserului.
0 commit comments