Transitioning from RequireJS to browserify (along with babelify) has led me to rewrite my current modules as classes. Each of my RequireJS modules has a method named eventHandler
that manages module-specific events. However, when extending a class, the subclass's eventHandler
is called twice - once by the parent class and again by the subclass.
Parent class:
'use strict';
class Tooltip {
constructor() {
this.eventHandler();
}
eventHandler() {
// Module specific events
}
}
module.exports = Tooltip;
Subclass:
'use strict';
import Tooltip from './Tooltip';
class Block extends Tooltip {
constructor() {
super();
this.eventHandler();
}
eventHandler() {
// Module specific events
// Gets called twice
}
}
module.exports = Block;
I appreciate the simplicity of having the eventHandler method consistently named across all modules for easier maintenance. Is there a recommended solution to prevent the method from being invoked twice in this scenario? Thank you for any advice!