Use .bind instead of () => {}
This commit is contained in:
parent
fc08cd74fe
commit
8bc1a40914
@ -100,10 +100,10 @@ class Backend {
|
|||||||
this.onOptionsUpdated('background');
|
this.onOptionsUpdated('background');
|
||||||
|
|
||||||
if (isObject(chrome.commands) && isObject(chrome.commands.onCommand)) {
|
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)) {
|
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));
|
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class Backend {
|
|||||||
this.isPreparedResolve = null;
|
this.isPreparedResolve = null;
|
||||||
this.isPreparedPromise = null;
|
this.isPreparedPromise = null;
|
||||||
|
|
||||||
this.clipboardMonitor.onClipboardText = (text) => this._onClipboardText(text);
|
this.clipboardMonitor.onClipboardText = this._onClipboardText.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
onOptionsUpdated(source) {
|
onOptionsUpdated(source) {
|
||||||
|
@ -93,18 +93,18 @@ class DisplaySearch extends Display {
|
|||||||
} else {
|
} else {
|
||||||
this.clipboardMonitorEnable.checked = false;
|
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));
|
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
||||||
|
|
||||||
this.search.addEventListener('click', (e) => this.onSearch(e), false);
|
this.search.addEventListener('click', this.onSearch.bind(this), false);
|
||||||
this.query.addEventListener('input', () => this.onSearchInput(), false);
|
this.query.addEventListener('input', this.onSearchInput.bind(this), false);
|
||||||
this.wanakanaEnable.addEventListener('change', (e) => this.onWanakanaEnableChange(e));
|
this.wanakanaEnable.addEventListener('change', this.onWanakanaEnableChange.bind(this));
|
||||||
window.addEventListener('popstate', (e) => this.onPopState(e));
|
window.addEventListener('popstate', this.onPopState.bind(this));
|
||||||
window.addEventListener('copy', (e) => this.onCopy(e));
|
window.addEventListener('copy', this.onCopy.bind(this));
|
||||||
|
|
||||||
this.clipboardMonitor.onClipboardText = (text) => this.onExternalSearchUpdate(text);
|
this.clipboardMonitor.onClipboardText = this.onExternalSearchUpdate.bind(this);
|
||||||
|
|
||||||
this.updateSearchButton();
|
this.updateSearchButton();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -37,7 +37,7 @@ AudioSourceUI.Container = class Container {
|
|||||||
this.children.push(new AudioSourceUI.AudioSource(this, audioSource, this.children.length));
|
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);
|
this.addButton.addEventListener('click', this._clickListener, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ AudioSourceUI.AudioSource = class AudioSource {
|
|||||||
|
|
||||||
this.select.value = audioSource;
|
this.select.value = audioSource;
|
||||||
|
|
||||||
this._selectChangeListener = () => this.onSelectChanged();
|
this._selectChangeListener = this.onSelectChanged.bind(this);
|
||||||
this._removeClickListener = () => this.onRemoveClicked();
|
this._removeClickListener = this.onRemoveClicked.bind(this);
|
||||||
|
|
||||||
this.select.addEventListener('change', this._selectChangeListener, false);
|
this.select.addEventListener('change', this._selectChangeListener, false);
|
||||||
this.removeButton.addEventListener('click', this._removeClickListener, false);
|
this.removeButton.addEventListener('click', this._removeClickListener, false);
|
||||||
|
@ -41,7 +41,7 @@ ConditionsUI.Container = class Container {
|
|||||||
this.children.push(new ConditionsUI.ConditionGroup(this, conditionGroup));
|
this.children.push(new ConditionsUI.ConditionGroup(this, conditionGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addButton.on('click', () => this.onAddConditionGroup());
|
this.addButton.on('click', this.onAddConditionGroup.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -127,7 +127,7 @@ ConditionsUI.ConditionGroup = class ConditionGroup {
|
|||||||
this.children.push(new ConditionsUI.Condition(this, condition));
|
this.children.push(new ConditionsUI.Condition(this, condition));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addButton.on('click', () => this.onAddCondition());
|
this.addButton.on('click', this.onAddCondition.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -185,10 +185,10 @@ ConditionsUI.Condition = class Condition {
|
|||||||
this.updateOperators();
|
this.updateOperators();
|
||||||
this.updateInput();
|
this.updateInput();
|
||||||
|
|
||||||
this.input.on('change', () => this.onInputChanged());
|
this.input.on('change', this.onInputChanged.bind(this));
|
||||||
this.typeSelect.on('change', () => this.onConditionTypeChanged());
|
this.typeSelect.on('change', this.onConditionTypeChanged.bind(this));
|
||||||
this.operatorSelect.on('change', () => this.onConditionOperatorChanged());
|
this.operatorSelect.on('change', this.onConditionOperatorChanged.bind(this));
|
||||||
this.removeButton.on('click', () => this.onRemoveClicked());
|
this.removeButton.on('click', this.onRemoveClicked.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
@ -36,7 +36,7 @@ class SettingsDictionaryListUI {
|
|||||||
this.dictionaryEntries = [];
|
this.dictionaryEntries = [];
|
||||||
this.extra = null;
|
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) {
|
setOptionsDictionaries(optionsDictionaries) {
|
||||||
@ -198,10 +198,10 @@ class SettingsDictionaryEntryUI {
|
|||||||
|
|
||||||
this.applyValues();
|
this.applyValues();
|
||||||
|
|
||||||
this.eventListeners.addEventListener(this.enabledCheckbox, 'change', (e) => this.onEnabledChanged(e), false);
|
this.eventListeners.addEventListener(this.enabledCheckbox, 'change', this.onEnabledChanged.bind(this), false);
|
||||||
this.eventListeners.addEventListener(this.allowSecondarySearchesCheckbox, 'change', (e) => this.onAllowSecondarySearchesChanged(e), false);
|
this.eventListeners.addEventListener(this.allowSecondarySearchesCheckbox, 'change', this.onAllowSecondarySearchesChanged.bind(this), false);
|
||||||
this.eventListeners.addEventListener(this.priorityInput, 'change', (e) => this.onPriorityChanged(e), false);
|
this.eventListeners.addEventListener(this.priorityInput, 'change', this.onPriorityChanged.bind(this), false);
|
||||||
this.eventListeners.addEventListener(this.deleteButton, 'click', (e) => this.onDeleteButtonClicked(e), false);
|
this.eventListeners.addEventListener(this.deleteButton, 'click', this.onDeleteButtonClicked.bind(this), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
@ -44,7 +44,7 @@ class SettingsPopupPreview {
|
|||||||
|
|
||||||
async prepare() {
|
async prepare() {
|
||||||
// Setup events
|
// 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');
|
const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox');
|
||||||
if (themeDarkCheckbox !== null) {
|
if (themeDarkCheckbox !== null) {
|
||||||
@ -52,7 +52,7 @@ class SettingsPopupPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite API functions
|
// Overwrite API functions
|
||||||
window.apiOptionsGet = (...args) => this.apiOptionsGet(...args);
|
window.apiOptionsGet = this.apiOptionsGet.bind(this);
|
||||||
|
|
||||||
// Overwrite frontend
|
// Overwrite frontend
|
||||||
const popupHost = new PopupProxyHost();
|
const popupHost = new PopupProxyHost();
|
||||||
@ -62,7 +62,7 @@ class SettingsPopupPreview {
|
|||||||
this.popup.setChildrenSupported(false);
|
this.popup.setChildrenSupported(false);
|
||||||
|
|
||||||
this.popupSetCustomOuterCssOld = this.popup.setCustomOuterCss;
|
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);
|
this.frontend = new Frontend(this.popup);
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ class DisplayFloat extends Display {
|
|||||||
['setContentScale', ({scale}) => this.setContentScale(scale)]
|
['setContentScale', ({scale}) => this.setContentScale(scale)]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
yomichan.on('orphaned', () => this.onOrphaned());
|
yomichan.on('orphaned', this.onOrphaned.bind(this));
|
||||||
window.addEventListener('message', (e) => this.onMessage(e), false);
|
window.addEventListener('message', this.onMessage.bind(this), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepare(options, popupInfo, url, childrenSupported, scale, uniqueId) {
|
async prepare(options, popupInfo, url, childrenSupported, scale, uniqueId) {
|
||||||
|
@ -64,9 +64,9 @@ class Frontend extends TextScanner {
|
|||||||
window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));
|
window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
yomichan.on('orphaned', () => this.onOrphaned());
|
yomichan.on('orphaned', this.onOrphaned.bind(this));
|
||||||
yomichan.on('optionsUpdated', () => this.updateOptions());
|
yomichan.on('optionsUpdated', this.updateOptions.bind(this));
|
||||||
yomichan.on('zoomChanged', (e) => this.onZoomChanged(e));
|
yomichan.on('zoomChanged', this.onZoomChanged.bind(this));
|
||||||
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
||||||
|
|
||||||
this._updateContentScale();
|
this._updateContentScale();
|
||||||
|
@ -260,7 +260,7 @@ class Popup {
|
|||||||
'mozfullscreenchange',
|
'mozfullscreenchange',
|
||||||
'webkitfullscreenchange'
|
'webkitfullscreenchange'
|
||||||
];
|
];
|
||||||
const onFullscreenChanged = () => this._onFullscreenChanged();
|
const onFullscreenChanged = this._onFullscreenChanged.bind(this);
|
||||||
for (const eventName of fullscreenEvents) {
|
for (const eventName of fullscreenEvents) {
|
||||||
this._fullscreenEventListeners.addEventListener(document, eventName, onFullscreenChanged, false);
|
this._fullscreenEventListeners.addEventListener(document, eventName, onFullscreenChanged, false);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class WindowScroll {
|
|||||||
this.animationEndTime = 0;
|
this.animationEndTime = 0;
|
||||||
this.animationEndX = 0;
|
this.animationEndX = 0;
|
||||||
this.animationEndY = 0;
|
this.animationEndY = 0;
|
||||||
this.requestAnimationFrameCallback = (t) => this.onAnimationFrame(t);
|
this.requestAnimationFrameCallback = this.onAnimationFrame.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
toY(y) {
|
toY(y) {
|
||||||
|
Loading…
Reference in New Issue
Block a user