From 8818b19d52c03914ae015e8e53c62920476c06e8 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 20 Jul 2023 07:45:15 +0100 Subject: [PATCH] Use arrow functions to preserve `this` in timers --- src/javascripts/components/copy.mjs | 2 +- src/javascripts/components/options-table.mjs | 2 +- src/javascripts/components/search.mjs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/javascripts/components/copy.mjs b/src/javascripts/components/copy.mjs index 73670c17f8..bc6e8a57ff 100644 --- a/src/javascripts/components/copy.mjs +++ b/src/javascripts/components/copy.mjs @@ -27,7 +27,7 @@ Copy.prototype.copyAction = function () { }).on('success', function (e) { e.trigger.textContent = 'Code copied' e.clearSelection() - setTimeout(function () { + setTimeout(() => { e.trigger.textContent = 'Copy code' }, 5000) }) diff --git a/src/javascripts/components/options-table.mjs b/src/javascripts/components/options-table.mjs index 6f7758898e..993a500c37 100644 --- a/src/javascripts/components/options-table.mjs +++ b/src/javascripts/components/options-table.mjs @@ -44,7 +44,7 @@ const OptionsTable = { } detailsText.style.display = '' - window.setTimeout(function () { + window.setTimeout(() => { tabLink.focus() if (isLinkToTable) document.querySelector(hash).scrollIntoView() }, 0) diff --git a/src/javascripts/components/search.mjs b/src/javascripts/components/search.mjs index cad737321a..cdf6f291c9 100644 --- a/src/javascripts/components/search.mjs +++ b/src/javascripts/components/search.mjs @@ -76,7 +76,7 @@ Search.prototype.handleSearchQuery = function (query, callback) { searchCallback = callback clearTimeout(inputDebounceTimer) - inputDebounceTimer = setTimeout(function () { + inputDebounceTimer = setTimeout(() => { trackSearchResults(searchQuery, searchResults) }, DEBOUNCE_TIME_TO_WAIT())