I am developing a project in Typescript that has two classes like this:
class A{
//some attributes
function_to_pass(){
//Do something
this.someFunction();
//Make changes in object A
}
protected someFunction(){
//Do some stuff
}
}
class B{
private readonly _functionProvided: () => void;
constructor(functionProvided: () => void){
this._functionPassed = functionProvided;
}
private myFunction(){
//Do some stuff
this._functionProvided();
}
}
I want the object of class B to call the "function_to_pass" method in the object of class A, so i pass the function as a parameter in the constructor and then call "myFunction" in this object b. Like this
objectA = new A();
objectB = new B(objectA.function_to_pass)
objectB.myFunction()
But, i get the following error:
TypeError: this.someFunction is not a function
I suppose that objectB does not know about objectA, so objectB can't manipulate objectA.
Is there anyway i can do this?