Use .bind instead of () => {}

This commit is contained in:
toasted-nutbread 2020-02-26 21:01:40 -05:00
parent fc08cd74fe
commit 8bc1a40914
10 changed files with 34 additions and 34 deletions

View File

@ -100,10 +100,10 @@ class Backend {
this.onOptionsUpdated('background');
if (isObject(chrome.commands) && isObject(chrome.commands.onCommand)) {
chrome.commands.onCommand.addListener((command) => this._runCommand(command));
chrome.commands.onCommand.addListener(this._runCommand.bind(this));
}
if (isObject(chrome.tabs) && isObject(chrome.tabs.onZoomChange)) {
chrome.tabs.onZoomChange.addListener((info) => this._onZoomChange(info));
chrome.tabs.onZoomChange.addListener(this._onZoomChange.bind(this));
}
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
@ -116,7 +116,7 @@ class Backend {
this.isPreparedResolve = null;
this.isPreparedPromise = null;
this.clipboardMonitor.onClipboardText = (text) => this._onClipboardText(text);
this.clipboardMonitor.onClipboardText = this._onClipboardText.bind(this);
}
onOptionsUpdated(source) {

View File

@ -93,18 +93,18 @@ class DisplaySearch extends Display {
} else {
this.clipboardMonitorEnable.checked = false;
}
this.clipboardMonitorEnable.addEventListener('change', (e) => this.onClipboardMonitorEnableChange(e));
this.clipboardMonitorEnable.addEventListener('change', this.onClipboardMonitorEnableChange.bind(this));
}
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
this.search.addEventListener('click', (e) => this.onSearch(e), false);
this.query.addEventListener('input', () => this.onSearchInput(), false);
this.wanakanaEnable.addEventListener('change', (e) => this.onWanakanaEnableChange(e));
window.addEventListener('popstate', (e) => this.onPopState(e));
window.addEventListener('copy', (e) => this.onCopy(e));
this.search.addEventListener('click', this.onSearch.bind(this), false);
this.query.addEventListener('input', this.onSearchInput.bind(this), false);
this.wanakanaEnable.addEventListener('change', this.onWanakanaEnableChange.bind(this));
window.addEventListener('popstate', this.onPopState.bind(this));
window.addEventListener('copy', this.onCopy.bind(this));
this.clipboardMonitor.onClipboardText = (text) => this.onExternalSearchUpdate(text);
this.clipboardMonitor.onClipboardText = this.onExternalSearchUpdate.bind(this);
this.updateSearchButton();
} catch (e) {

View File

@ -37,7 +37,7 @@ AudioSourceUI.Container = class Container {
this.children.push(new AudioSourceUI.AudioSource(this, audioSource, this.children.length));
}
this._clickListener = () => this.onAddAudioSource();
this._clickListener = this.onAddAudioSource.bind(this);
this.addButton.addEventListener('click', this._clickListener, false);
}
@ -105,8 +105,8 @@ AudioSourceUI.AudioSource = class AudioSource {
this.select.value = audioSource;
this._selectChangeListener = () => this.onSelectChanged();
this._removeClickListener = () => this.onRemoveClicked();
this._selectChangeListener = this.onSelectChanged.bind(this);
this._removeClickListener = this.onRemoveClicked.bind(this);
this.select.addEventListener('change', this._selectChangeListener, false);
this.removeButton.addEventListener('click', this._removeClickListener, false);

View File

@ -41,7 +41,7 @@ ConditionsUI.Container = class Container {
this.children.push(new ConditionsUI.ConditionGroup(this, conditionGroup));
}
this.addButton.on('click', () => this.onAddConditionGroup());
this.addButton.on('click', this.onAddConditionGroup.bind(this));
}
cleanup() {
@ -127,7 +127,7 @@ ConditionsUI.ConditionGroup = class ConditionGroup {
this.children.push(new ConditionsUI.Condition(this, condition));
}
this.addButton.on('click', () => this.onAddCondition());
this.addButton.on('click', this.onAddCondition.bind(this));
}
cleanup() {
@ -185,10 +185,10 @@ ConditionsUI.Condition = class Condition {
this.updateOperators();
this.updateInput();
this.input.on('change', () => this.onInputChanged());
this.typeSelect.on('change', () => this.onConditionTypeChanged());
this.operatorSelect.on('change', () => this.onConditionOperatorChanged());
this.removeButton.on('click', () => this.onRemoveClicked());
this.input.on('change', this.onInputChanged.bind(this));
this.typeSelect.on('change', this.onConditionTypeChanged.bind(this));
this.operatorSelect.on('change', this.onConditionOperatorChanged.bind(this));
this.removeButton.on('click', this.onRemoveClicked.bind(this));
}
cleanup() {

View File

@ -36,7 +36,7 @@ class SettingsDictionaryListUI {
this.dictionaryEntries = [];
this.extra = null;
document.querySelector('#dict-delete-confirm').addEventListener('click', (e) => this.onDictionaryConfirmDelete(e), false);
document.querySelector('#dict-delete-confirm').addEventListener('click', this.onDictionaryConfirmDelete.bind(this), false);
}
setOptionsDictionaries(optionsDictionaries) {
@ -198,10 +198,10 @@ class SettingsDictionaryEntryUI {
this.applyValues();
this.eventListeners.addEventListener(this.enabledCheckbox, 'change', (e) => this.onEnabledChanged(e), false);
this.eventListeners.addEventListener(this.allowSecondarySearchesCheckbox, 'change', (e) => this.onAllowSecondarySearchesChanged(e), false);
this.eventListeners.addEventListener(this.priorityInput, 'change', (e) => this.onPriorityChanged(e), false);
this.eventListeners.addEventListener(this.deleteButton, 'click', (e) => this.onDeleteButtonClicked(e), false);
this.eventListeners.addEventListener(this.enabledCheckbox, 'change', this.onEnabledChanged.bind(this), false);
this.eventListeners.addEventListener(this.allowSecondarySearchesCheckbox, 'change', this.onAllowSecondarySearchesChanged.bind(this), false);
this.eventListeners.addEventListener(this.priorityInput, 'change', this.onPriorityChanged.bind(this), false);
this.eventListeners.addEventListener(this.deleteButton, 'click', this.onDeleteButtonClicked.bind(this), false);
}
cleanup() {

View File

@ -44,7 +44,7 @@ class SettingsPopupPreview {
async prepare() {
// Setup events
window.addEventListener('message', (e) => this.onMessage(e), false);
window.addEventListener('message', this.onMessage.bind(this), false);
const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox');
if (themeDarkCheckbox !== null) {
@ -52,7 +52,7 @@ class SettingsPopupPreview {
}
// Overwrite API functions
window.apiOptionsGet = (...args) => this.apiOptionsGet(...args);
window.apiOptionsGet = this.apiOptionsGet.bind(this);
// Overwrite frontend
const popupHost = new PopupProxyHost();
@ -62,7 +62,7 @@ class SettingsPopupPreview {
this.popup.setChildrenSupported(false);
this.popupSetCustomOuterCssOld = this.popup.setCustomOuterCss;
this.popup.setCustomOuterCss = (...args) => this.popupSetCustomOuterCss(...args);
this.popup.setCustomOuterCss = this.popupSetCustomOuterCss.bind(this);
this.frontend = new Frontend(this.popup);

View File

@ -51,8 +51,8 @@ class DisplayFloat extends Display {
['setContentScale', ({scale}) => this.setContentScale(scale)]
]);
yomichan.on('orphaned', () => this.onOrphaned());
window.addEventListener('message', (e) => this.onMessage(e), false);
yomichan.on('orphaned', this.onOrphaned.bind(this));
window.addEventListener('message', this.onMessage.bind(this), false);
}
async prepare(options, popupInfo, url, childrenSupported, scale, uniqueId) {

View File

@ -64,9 +64,9 @@ class Frontend extends TextScanner {
window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));
}
yomichan.on('orphaned', () => this.onOrphaned());
yomichan.on('optionsUpdated', () => this.updateOptions());
yomichan.on('zoomChanged', (e) => this.onZoomChanged(e));
yomichan.on('orphaned', this.onOrphaned.bind(this));
yomichan.on('optionsUpdated', this.updateOptions.bind(this));
yomichan.on('zoomChanged', this.onZoomChanged.bind(this));
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
this._updateContentScale();

View File

@ -260,7 +260,7 @@ class Popup {
'mozfullscreenchange',
'webkitfullscreenchange'
];
const onFullscreenChanged = () => this._onFullscreenChanged();
const onFullscreenChanged = this._onFullscreenChanged.bind(this);
for (const eventName of fullscreenEvents) {
this._fullscreenEventListeners.addEventListener(document, eventName, onFullscreenChanged, false);
}

View File

@ -26,7 +26,7 @@ class WindowScroll {
this.animationEndTime = 0;
this.animationEndX = 0;
this.animationEndY = 0;
this.requestAnimationFrameCallback = (t) => this.onAnimationFrame(t);
this.requestAnimationFrameCallback = this.onAnimationFrame.bind(this);
}
toY(y) {