Lassen Sie mich wissen, den Unterschied zwischen dem Setzen von clearTimeout und dem Setzen der gleichen Variablen wie null, die zum Festlegen der ID von settimeout verwendet wird.Einstellung clearTimeOut
Ich habe eine Funktion in unterscore.js unten erwähnt.
function debounce(func, wait, immediate) {
var timeout, args, context, timestamp, result;
var later = function() {
var last = new Date().getTime() - timestamp;
if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function() {
context = this;
args = arguments;
timestamp = new Date().getTime();
var callNow = immediate && !timeout;
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
};
Es setzt letztlich "Timeout" Variable als "Null" anstelle von ClearTimeOut.
Danke für die Annahme meiner Antwort, es ist nicht sehr klar, also wenn irgendwelche Community-Mitglieder es bearbeiten möchten, fühlen Sie sich frei. – PaulBGD