mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 00:18:12 +00:00
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:
committed by
Tim Abbott
parent
9840803c00
commit
6de39ae92d
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user