Skip to content

Commit 8a64840

Browse files
committed
Finished Throttle
1 parent ec24e0e commit 8a64840

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

JS/JS-br.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,50 +1125,50 @@ A implementação completa da ƒunção não é tão difícil.
11251125
11261126
# Throttle
11271127
1128-
`Debounce` and `Throttle` are different in nature. `Debounce` is to turn multiple executions into one last execution, and `Throttle` is to turn multiple executions into executions at regular intervals.
1128+
`Debounce` e `Throttle` possuem naturezas diferentes. `Debounce` é para tornar multiplas execuções na última execução, e `Throttle` é para tornar multiplas execuções em uma execução de intervalos regulares.
11291129
11301130
```js
1131-
// The first two parameters with debounce are the same function
1132-
// options: You can pass two properties
1133-
// trailing: Last time does not execute
1134-
// leading: First time does not execute
1135-
// The two properties cannot coexist, otherwise the function cannot be executed
1131+
// Os dois primeiro parâmetros com debounce são a mesma função
1132+
// options: você pode passar duas propriedades
1133+
// trailing: o último tempo não é executado
1134+
// leading: o primeiro tempo não é executado
1135+
// As duas propriedades não coexistem, contudo a função não será executada
11361136
_.throttle = function(func, wait, options) {
11371137
var context, args, result;
11381138
var timeout = null;
1139-
// Previous timestamp
1139+
// timestamp anterior
11401140
var previous = 0;
1141-
// Set empty if options is not passed
1141+
// Defina vázio se as opções não forem passadas
11421142
if (!options) options = {};
1143-
// Timer callback function
1143+
// Função Timer callback
11441144
var later = function() {
1145-
// If you set `leading`, then set `previous` to zero
1146-
// The first `if` statement of the following function is used
1145+
// se você definiu `leading`, então defina `previous` para zero
1146+
// O primeiro if da seguinte função é usada
11471147
previous = options.leading === false ? 0 : _.now();
1148-
// The first is prevented memory leaks and the second is judged the following timers when setting `timeout` to null
1148+
// O primeiro é prevenindo memory leaks e o segundo é julgado os seguintes timers quando configurado `timeout` para null
11491149
timeout = null;
11501150
result = func.apply(context, args);
11511151
if (!timeout) context = args = null;
11521152
};
11531153
return function() {
1154-
// Get current timestamp
1154+
// Obtenha o timestamp atual
11551155
var now = _.now();
1156-
// It must be true when it entering firstly
1157-
// If you do not need to execute the function firstly
1158-
// Set the last timestamp to current
1159-
// Then it will be greater than 0 when the remaining time is calculated next
1156+
// Deve ser verdado quando entrar pela primeira vez
1157+
// Se você não precisa executar essa função na primeira vez
1158+
// Defina o último timestamp para o atual
1159+
// Então ele será maior que 0 quando o termo remanecente for calculado da próxima vez
11601160
if (!previous && options.leading === false)
11611161
previous = now;
11621162
var remaining = wait - (now - previous);
11631163
context = this;
11641164
args = arguments;
1165-
// This condition will only be entered if it set `trailing`
1166-
// This condition will be entered firstly if it not set `leading`
1167-
// Another point, you may think that this condition will not be entered if you turn on the timer
1168-
// In fact, it will still enter because the timer delay is not accurate
1169-
// It is very likely that you set 2 seconds, but it needs 2.2 seconds to trigger, then this time will enter this condition
1165+
// Essa condição só será preenchida se definido para `trailing`
1166+
// Essa condição só será preenchida no ínicio se não definido `leading`
1167+
// Outro ponto, você deve pensar que essa condição não será preenchida se você ligar o timer
1168+
// De fato, será assim até entrar porque o atraso do timer não é acurado
1169+
// Isso é muito como se você setar a 2 segundos, mas ele precisa 2.2 segundos para disparar, então o tempo será preenchido nessa condição
11701170
if (remaining <= 0 || remaining > wait) {
1171-
// Clean up if there exist a timer otherwise it call twice callback
1171+
// Limpe se existe um timer e ele chama a callback duas vezes
11721172
if (timeout) {
11731173
clearTimeout(timeout);
11741174
timeout = null;
@@ -1177,8 +1177,8 @@ _.throttle = function(func, wait, options) {
11771177
result = func.apply(context, args);
11781178
if (!timeout) context = args = null;
11791179
} else if (!timeout && options.trailing !== false) {
1180-
// Judgment whether timer and trailing are set
1181-
// And you can't set leading and trailing at the same time
1180+
// Julge se o timer e trailing forem definidos
1181+
// E você não pode defirnor leading e trailing no mesmo instante
11821182
timeout = setTimeout(later, remaining);
11831183
}
11841184
return result;

0 commit comments

Comments
 (0)