Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d29907f

Browse files
committed
UPDATE
1 parent 40760d9 commit d29907f

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

‎JS/JS-br.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,10 @@ console.log(b.next()); // > { value: 3, done: false }
10151015
console.log(b.next()); // > { value: undefined, done: true }
10161016
```
10171017
1018-
As we can tell from the above code, a function with a `*` would have the `next` function execution. In other words, the execution of the function returns an object. Every call to the `next` function can resume executing the paused code. A simple implementation of the Generator function is shown below:
1019-
1018+
Como podemos dizer no código acima, a função com um `*` teria a execução da função `next`. Em outras palavras, a execução de função retorna um objeto. Toda chamada a função `next` pode continuar a execução do código pausado. Um simples implementação da função Generator é mostrada abaixo:
10201019
```js
10211020
// cb is the compiled 'test' function
1021+
// cb é a função 'test' compilada
10221022
function generator(cb) {
10231023
return (function() {
10241024
var object = {
@@ -1038,23 +1038,23 @@ function generator(cb) {
10381038
};
10391039
})();
10401040
}
1041-
// After babel's compilation, 'test' function turns into this:
1041+
// Depois da compilação do babel's, a função 'test' retorna dentro dessa:
10421042
function test() {
10431043
var a;
10441044
return generator(function(_context) {
10451045
while (1) {
10461046
switch ((_context.prev = _context.next)) {
1047-
// yield splits the code into several blocks
1048-
// every 'next' call executes one block of clode
1049-
// and indicates the next block to execute
1047+
// yield separa o código em diversos blocos
1048+
// cada chamada 'next' executa um bloco de código
1049+
// e indica o próximo bloco a ser executado
10501050
case 0:
10511051
a = 1 + 2;
10521052
_context.next = 4;
10531053
return 2;
10541054
case 4:
10551055
_context.next = 6;
10561056
return 3;
1057-
// execution complete
1057+
// execução completa
10581058
case 6:
10591059
case "end":
10601060
return _context.stop();
@@ -1066,30 +1066,30 @@ function test() {
10661066
10671067
# Debouncing
10681068
1069-
Have you ever encountered this problem in your development: how to do a complex computation in a scrolling event or to prevent the "second accidental click" on a button?
1069+
Tendo você encontrado esse problema e seu dia-a-dia no desenvolvimento: como fazer uma computação complexa em um evento de scroll ou prevenir o "segundo clique acidental" no butão?
10701070
1071-
These requirements can be achieved with function debouncing. Especially for the first one, if complex computations are carried out in frequent event callbacks, there's a large chance that the page becomes laggy. It's better to combine multiple computations into a single one, and only operate at particular time. Since there are many libraries that implement debouncing, we won't build our own here and will just take underscore's source code to explain debouncing:
1071+
Esses requisitos podem ser alcançados com funcões debouncing. Especialmente para o primeiro, se uma computação complexa estiver sendo chamado em frequentes eventos de callbacks, existe uma grande chance que a página se torne lenta. É melhor combinar essas multiplas computações e uma, e apenas operar em determinado periodo de tempo. Desde que existe muitas bibliotecas que implementam debouncing, nós não construimos nosso próprio aqui e vamos pegar o código do underscore para explicar o debouncing:
10721072
10731073
```js
10741074
/**
1075-
* underscore's debouncing function. When the callback function is called in series, func will only execute when the idel time is larger or equal to `wait`.
1075+
* função underscore debouncing. Quando a função callback é chamada em série, a funcão vai executar apenas quando o tempo ideal é maior ou igual ao `wait`.
10761076
*
1077-
* @param {function} func callback function
1078-
* @param {number} wait length of waiting intervals
1079-
* @param {boolean} immediate when set to true, func is executed immediately
1080-
* @return {function} returns the function to be called by the client
1077+
* @param {function} func função callback
1078+
* @param {number} wait tamanho do intervalo de espera
1079+
* @param {boolean} immediate quando definido para true, func é executada imadiatamente
1080+
* @return {function} retorna a função a ser chamada pelo cliente
10811081
*/
10821082
_.debounce = function(func, wait, immediate) {
10831083
var timeout, args, context, timestamp, result;
10841084

10851085
var later = function() {
1086-
// compare now to the last timestamp
1086+
// compara now para o último timestamp
10871087
var last = _.now() - timestamp;
1088-
// if the current time interval is smaller than the set interval and larger than 0, then reset the timer.
1088+
// se o tempo de intervalo atual é menor então o set interval é maior que 0, então reinicie o timer.
10891089
if (last < wait && last >= 0) {
10901090
timeout = setTimeout(later, wait - last);
10911091
} else {
1092-
// otherwise it's time to execute the callback function
1092+
// senão é o momento de executar a função callback
10931093
timeout = null;
10941094
if (!immediate) {
10951095
result = func.apply(context, args);
@@ -1101,14 +1101,14 @@ _.debounce = function(func, wait, immediate) {
11011101
return function() {
11021102
context = this;
11031103
args = arguments;
1104-
// obtain the timestamp
1104+
// obtendo o timestamp
11051105
timestamp = _.now();
1106-
// if the timer doesn't exist then execute the function immediately
1106+
// se o timer não existir então execute a função imediatamente
11071107
var callNow = immediate && !timeout;
1108-
// if the timer doesn't exist then create one
1108+
// se o time não existe então crie um
11091109
if (!timeout) timeout = setTimeout(later, wait);
11101110
if (callNow) {
1111-
// if the immediate execution is needed, use apply to start the function
1111+
// se a função imediata é precisa, use aplly para começar a função
11121112
result = func.apply(context, args);
11131113
context = args = null;
11141114
}
@@ -1118,6 +1118,11 @@ _.debounce = function(func, wait, immediate) {
11181118
};
11191119
```
11201120
1121+
A implementação completa da ƒunção não é tão difícil.
1122+
1123+
- Para a implementação de proteger contra clicks acidentais: enquanto eu começar o time e o time existir, não importa quantas vezes eu clicar o butão, a função de callback não será executada. Contudo quando o time termina, é setado para `null`, outro click é permitido.
1124+
-
1125+
11211126
The complete function implementation is not too difficult. Let's summarize here.
11221127
11231128
- For the implementation of protecting against accidental clicks: as long as I start a timer and the timer is there, no matter how you click the button, the callback function won't be executed. Whenever the timer ends and is set to `null`, another click is allowed.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /