I have developed a function that manages various tasks related to paginating and sorting a table. This function includes a key method that executes the database query and updates the display table.
I aim to access this inner function/method from within the function itself, as well as externally through the object that was created.
handleFunction = function() {
mainMethod = function() {
console.log('you found me');
};
document.getElementById('test').addEventListener('click', function (e) {
mainMethod();
});
mainMethod();
};
myHandler = new handleFunction();
myHandler.mainMethod();
handleFunction = function() {
this.mainMethod = function() {
console.log('you found me');
};
document.getElementById('test').addEventListener('click', function (e) {
// would need to use bind here, which can complicate things
mainMethod();
});
this.mainMethod();
};
myHandler= new DrawShape();
myHandler.mainMethod();
The first approach allows global accessibility of the mainMethod function within handleFunction, but it cannot be called from outside.
The second approach enables calling myTest.mainMethod externally, but using it within an inner function requires binding, causing complications in maintaining target accuracy.
Is there a more efficient solution?