Having a calendar
widget written in TypeScript
, I am able to bind a listener to a separate function. However, I desire this separate function to have default functionality until someone overrides it in the config
object passed to the constructor. Within the constructor, I pass something similar:
{
container: 'xxx',
cellClick: function(sender, event, data) {
// custom functionality
}
}
How can I define a function cellClick
in my base class and when rendering my td
cells, bind an event listener to this function and pass some data for the cell which will have default functionality initially, but allow for override if the function is defined in the object for the clicked cell.
I attempted something like that, but it binds the listener directly to the config
function. I believe it could be easily achieved within my setter
, but I cannot figure out how.
td.addEventListener('click', function () {
this.config.cellClick(td, event, data);
})
EDIT:
Here's my abstract
class which extends the Table
class responsible for creating objects for thead, tbody, and tfoot
:
// Abstract class code here...
Furthermore, there is a class Calendar
extending the abstract class and serving as the main class instanced with the configuration object.
// Calendar class code here...
There are 3 additional classes for the view
render and logic handling, all working with the table object to perform various operations.
Lastly, here is how I initialize it:
// Initialization code here...
Since I'm not very experienced with OOP, any suggestions for refactoring would be greatly appreciated.