I am implementing a credit card payment form in ReactJS using a 3rd party bank JS which works using iframes.
The logic is I load bank's javascript in my page, something like this:
<script src="https://my-bank.com/super-secure-script.js"></script>
Then I collect user's CC data in my ReactJS component, then call a function like this:
window.Bank.SendPayment(CC, this.paymentCompletedCallback);
...
paymentCompletedCallback = (result) => {
// process payment result here, inside my component
}
The problem is: the code inside super-secure-script.js cannot find the callback this.paymentCompletedCallback, because it is inside inside my component.
The question is: how can I pass to an external script a reference to a react object function?
thisbinding for fat arrow is a misconception (I believe), it dont have its ownthisthus bubbles up to use parent'sthiswhich in case ofasyncgets lost and undefined most likely.binddid the trick! I did never really understood thatbindthing, sorry for wasting your time! If @Lumpenstein want to post his first comment a an answer, I will accept it... Many thanks to @Rikin, too!