I'm trying to encapsulate common functionality in base class and planning to invoke derived class specific function from their respective instances. Somehow, I'm not getting parameters in derived class. not sure what's wrong here -
class A {
constructor(callback){
this.callback = callback;
}
write(){
console.log('Writing A');
this.callback(10);
}
}
class B extends A {
constructor(){
super(()=> this.read())
}
read(n){
console.log('Read B: ' + n);
}
}
const b = new B();
b.write();
Output
"Writing A"
"Read B: undefined"
Whereas, I would expect -
"Writing A"
"Read B: 10"