This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the javascript category.
Last Updated: 2024-11-21
I was using a library for the payment provider PayPal. I was supposed to import the code in my HTML as such
<script src="paypal.com/sdk.js">
Then, to use the code, I would need to write something like the following:
payal.Buttons.create(...)
This would be easy if inside an inline script
tag following the bit above that
downloaded the PayPal SDK. But I was working with ES6 via WebPack.
My code here failed to compile because paypal
was not available in the context
provided (Specifically: this
was undefined
here).
The solution was to call paypal
on the window
object.
window.payal.Buttons.create(...)