From 37b6fa7a1b8c35aba19c9d69cdbdb9a03ecaa8c0 Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <svkn.87@gmail.com>
Date: Mon, 28 Feb 2022 16:57:32 +0530
Subject: [PATCH] DEV: refactor JS files to not use `self = this` in code.
 (#15095)

We no longer use this pattern. Instead, we can use javascript arrow functions.
---
 .../javascripts/discourse/app/components/topic-list.js     | 5 ++---
 app/assets/javascripts/discourse/app/lib/debounce.js       | 7 +++----
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js
index 90a7ff07a14..67357e44699 100644
--- a/app/assets/javascripts/discourse/app/components/topic-list.js
+++ b/app/assets/javascripts/discourse/app/components/topic-list.js
@@ -170,12 +170,11 @@ export default Component.extend(LoadMore, {
   },
 
   click(e) {
-    let self = this;
-    let onClick = function (sel, callback) {
+    const onClick = (sel, callback) => {
       let target = $(e.target).closest(sel);
 
       if (target.length === 1) {
-        callback.apply(self, [target]);
+        callback.apply(this, [target]);
       }
     };
 
diff --git a/app/assets/javascripts/discourse/app/lib/debounce.js b/app/assets/javascripts/discourse/app/lib/debounce.js
index 61592205631..15ad64a2d69 100644
--- a/app/assets/javascripts/discourse/app/lib/debounce.js
+++ b/app/assets/javascripts/discourse/app/lib/debounce.js
@@ -5,13 +5,12 @@ import { debounce } from "@ember/runloop";
   Original function will be called with the context and arguments from the last call made.
 **/
 export default function (func, wait) {
-  let self, args;
-  const later = function () {
-    func.apply(self, args);
+  let args;
+  const later = () => {
+    func.apply(this, args);
   };
 
   return function () {
-    self = this;
     args = arguments;
 
     debounce(null, later, wait);