js: Clean up typeof … === "undefined" checks.

The only reason to use typeof foo === "undefined" is when foo is a
global identifier that might not have been declared at all, so it
might raise a ReferenceError if evaluated.  For a variable declared
with const or let or import, a function argument, or a complex
expression, simply foo === undefined is equivalent.

Some of these conditions have become impossible and can be removed
entirely, and some can be replaced more idiomatically with default
parameters (note that JavaScript does not share the Python misfeature
of evaluating the default parameter at function declaration time).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-03-24 12:14:12 -07:00
committed by Tim Abbott
parent 9840803c00
commit 6de39ae92d
10 changed files with 17 additions and 25 deletions

View File

@@ -11,14 +11,14 @@ export function change_tab_to(tabname) {
export function place_caret_at_end(el) {
el.focus();
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
if (window.getSelection !== undefined && document.createRange !== undefined) {
const range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange !== "undefined") {
} else if (document.body.createTextRange !== undefined) {
const textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);