I've seen several questions about using "this" in classes and functions, but I don't think I've seen what I'm looking for in particular.
My situation is:
I'm calling a function from a third-party library in a class method. However, the third-party library function is calling callback.bind(this), and I need to have access to the context it's binding.
But I also want to be able to access class properties. Is this possible? If not, what are some potential workaround? Code outline looks something like:
class MyClass {
myProperty = 'something';
myMethod() {
console.log(this.myProperty);
}
otherMethod() {
thirdPartyLibrary.functionRequiringCallback(function() {
this.MyMethod(); //undefined
this.requiredThirdPartyFunction(); //"this" refers to thirdPartyLibrary
});
}
}
I could certainly make the callback an arrow function so that "this" refers to the class-scope, but then I won't have access to "requiredThirdPartyFunction".
Any help would be appreciated.