I have an abstract parent class Menu which passes a method (input) through process.stdin.on.
abstract class Menu extends RenderObject {
label: string;
constructor(label, priority, name) {
super(priority, name);
this.label = label;
stdin.setRawMode(true);
stdin.setEncoding(‘utf-8’);
stdin.on(‘data’, this.input);
}
abstract input(data: Buffer);
}
Within an implementation of that method, i am attempting to call this to reference an instance of the class.
input(data: any) {
switch(data){
case “<Arrow Up>”:
this.idx—;
break;
case “<Arrow Down>:
this.idx++;
break;
case “Ctrl+C”:
process.exit();
default:
return;
}
Renderer.render();
}
However this refers to stdin itself. (As I’ve verified by logging, won’t provide it here since it’s just process.stdin.
I’ve attempted passing the instance as a parameter in the function
input(data: any, host = this)
This pointed back to process.stdin.
And also attempted to set input via an arrow function
input = (data) => {/* code */}
This flagged typescripts checking regarding improper implementation and through “listener argument must be of type function” as an error.
How do i get around this?
All help is appreciated, thank you very much 