I was wondering is it a good practice to bind constant arguments to method in constructor or is there some better alternatives?
f.e.
constructor() {
super();
this.openModalWithFirstTabActive = this.openModal.bind(this, TAB.FIRST);
this.openModalWithSecondTabActive = this.openModal.bind(this, TAB.SECOND);
}
openModal(tabId) {
const {
openModal,
} = this.props;
/*
lots of logic and stuff
*/
openModal({
activeTabId: tabId,
...restProps,
});
}
EDIT
I'll provided more code and will describe my usage case for better understanding.
I've updated with openModal method, in my usecase it's much larger and has more logic in it.
So, i have a modal, in which there's two tabs. I have two buttons, open pressing button 1 modal needs to open and first tab needs to be active, upon pressing button 2 modal needs to open and second tab needs to be active.
I bind two methods in constructor which both call this.openModal only with different activeTabId specified. This avoids code duplication and arrow functions.
So my question would be is there any better alternative to this?