Calling private/public method from constructor in the same class gives me an error
Uncaught TypeError: this.setEventHandler is not a function at Object.Init (Init.ts:4) at :3:16
export class Init {
constructor(private connectBtn: HTMLElement) {
this.setEventHandler();
}
public setEventHandler() {
this.connectBtn.onclick = (e) => {
this.openConnectWindow();
}
}
private openConnectWindow() {
console.log("OPEN SESAME")
}
}
This is the compiled javascript
var Init = (function () {
function Init(connectBtn) {
this.connectBtn = connectBtn;
this.setEventHandler();
}
Init.prototype.setEventHandler = function () {
var _this = this;
this.connectBtn.onclick = function (e) {
_this.openConnectWindow();
};
};
Init.prototype.openConnectWindow = function () {
console.log("OPEN SESAME");
};
return Init;
}());
Edit: This is for a library.
I tried putting var mylib = new MyLibraryName() but I only get "MyLibraryName is not a constructor".
I start the root object with webpack
output: {
path: path.join(__dirname, "lib"),
filename: outputFile,
library: libraryName,
libraryTarget: "umd",
umdNamedDefine: true
},
Initclass instanses - degr