I'm moving from RequireJS to browserify (together with babelify) and try to rewrite my current modules to classes. For each of my RequireJS modules I have a method called eventHandler
which handles all module specific events. Now when I extend a class, the parent class calls the subclass`s eventHandler
method which leads to invoking the method twice.
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 liked the fact that the eventHandler method was named the same across all modules as it was easier to maintain. That's why I'd like to keep this pattern. So what would be the best way to solve this problem? Thanks for any suggestions!
See Question&Answers more detail:os