Here is the complete code:
export interface IButton {
click: Function;
settings?: IButtonSettings;
}
abstract class Button implements IButton {
click() {}
}
class ButtonReset extends Button {
super()
}
The component looks like this:
export class ButtonsComponent {
private message = "Alert Message";
constructor() {
let button = new ButtonReset();
button.click = this.showAlert;
button.click(); // This should log the value of 'message'
}
public showAlert() {
console.log(this.message);
}
}
Why am I unable to bind the method showAlert()
to an instance of new ButtonReset();
and then call it?
A simpler example:
class ClassA {
public text = "text 1";
public obj: any;
}
class ClassB {
public text = "text";
printText() {
console.log(this.text);
}
}
let instA = new ClassA();
let instB = new ClassB();
instA.obj = instB.printText;
instA.obj();
I want to access text
instead of text 1