I am looking for the correct way to implement a javascript class without using a specific framework (react, angular and ...), jQuery dependency injection and access the instance object in the class methods (using the this keyword) when assigning callbacks to events.
The implementation I did is as follows:
Parent class:
import autoBind from "./auto-bind.js";
class Tools {
constructor() {
autoBind(this);
}
init() { }
}
export default Tools;
Sub class:
import autoBind from "./auto-bind.js";
import Tools from "./tools.js"
import * as hub from "./hub.js"
class PanelTools extends Tools {
constructor() {
super();
autoBind(this);
}
async init() {
let _this = this;
super.init();
await hub.start();
$(document)
.ajaxStart(function () {
_this.showLoader();
});
}
showLoader() {
$("#loader").show();
}
}
It should be noted that I am not using a special framework (react,
angular and ...) here.I used the "auto-bind" library to bind
this
.I implemented the
async init()
method to call await functions.I defined the variable
_this
in the class methods to access the
instance.
Is it correct to implement these classes and use jquery in the methods?