From 02004c9b0f08e0e2835bfd7c828b7528dab7655c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 25 Oct 2019 15:26:37 -0700 Subject: [PATCH] js: Convert self-referential vars to const. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ESLint won’t convert these automatically because it can’t rule out a behavior difference arising from an access to a self-referential var before it’s initialized: > var x = (f => f())(() => x); undefined > let y = (f => f())(() => y); Thrown: ReferenceError: Cannot access 'y' before initialization at repl:1:26 at repl:1:15 Signed-off-by: Anders Kaseorg --- frontend_tests/zjsunit/zjquery.js | 2 +- static/js/feedback_widget.js | 2 +- static/js/input_pill.js | 2 +- static/js/lightbox_canvas.js | 2 +- static/js/list_render.js | 2 +- static/js/localstorage.js | 2 +- static/js/message_edit.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index e9764e21d6..9c4882db08 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -140,7 +140,7 @@ exports.make_new_elem = function (selector, opts) { var classes = new Dict(); var event_store = exports.make_event_store(selector); - var self = { + const self = { addClass: function (class_name) { classes.set(class_name, true); return self; diff --git a/static/js/feedback_widget.js b/static/js/feedback_widget.js index 6f321c62c3..3e1ff22d0c 100644 --- a/static/js/feedback_widget.js +++ b/static/js/feedback_widget.js @@ -26,7 +26,7 @@ var meta = { opened: false, }; -var animate = { +const animate = { maybe_close: function () { if (!meta.opened) { return; diff --git a/static/js/input_pill.js b/static/js/input_pill.js index 9c1c24fe82..625f33c70d 100644 --- a/static/js/input_pill.js +++ b/static/js/input_pill.js @@ -44,7 +44,7 @@ exports.create = function (opts) { // a dictionary of internal functions. Some of these are exposed as well, // and nothing in here should be assumed to be private (due to the passing) // of the `this` arg in the `Function.prototype.bind` use in the prototype. - var funcs = { + const funcs = { // return the value of the contenteditable input form. value: function (input_elem) { return input_elem.innerText.trim(); diff --git a/static/js/lightbox_canvas.js b/static/js/lightbox_canvas.js index ea7998d7ad..1dcead546e 100644 --- a/static/js/lightbox_canvas.js +++ b/static/js/lightbox_canvas.js @@ -29,7 +29,7 @@ window.onload = function () { }); }; -var funcs = { +const funcs = { setZoom: function (meta, zoom) { // condition to handle zooming event by zoom hotkeys if (zoom === '+') { diff --git a/static/js/list_render.js b/static/js/list_render.js index ca0cf78525..c39aac2b62 100644 --- a/static/js/list_render.js +++ b/static/js/list_render.js @@ -56,7 +56,7 @@ exports.create = function ($container, list, opts) { opts.filter = {}; } - var prototype = { + const prototype = { // Reads the provided list (in the scope directly above) // and renders the next block of messages automatically // into the specified contianer. diff --git a/static/js/localstorage.js b/static/js/localstorage.js index e69f74aa09..daacdb4be7 100644 --- a/static/js/localstorage.js +++ b/static/js/localstorage.js @@ -1,4 +1,4 @@ -var ls = { +const ls = { // parse JSON without throwing an error. parseJSON: function (str) { try { diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 0035fb95ae..b4e09567c1 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -375,7 +375,7 @@ function edit_message(row, raw_content) { // Do this right away, rather than waiting for the timer to do its first update, // since otherwise there is a noticeable lag message_edit_countdown_timer.text(timer_text(seconds_left)); - var countdown_timer = setInterval(function () { + const countdown_timer = setInterval(function () { seconds_left -= 1; if (seconds_left <= 0) { clearInterval(countdown_timer);