3 ms·
You're making the assumption that the person reading this is using modern JS tooling (not just writing vanilla JavaScript). What's proposed here, though verbose
by rglover 5y ago
You're making the assumption that the person reading this is using modern JS tooling (not just writing vanilla JavaScript). What's proposed here, though verbose, is a good way to teach type checking in JS without a dependency.
Tooling is a crutch. We should be teaching more of the above, not less.
- cnity 5y agoI agree, though I'd settle for: `if (stripe && stripe.handleCardPayment)` (I know the behaviour isn't identical, but checking the actual type is pointless in this case)
- chrismorgan 5y ago`if (window.stripe && stripe.handleCardPayment)`; just `stripe` may throw a ReferenceError if not loaded, while `window.stripe` will be `undefined` (appropriately falsy) if not loaded. (This is assuming a browser environment, where `window` is roughly the global object; see also `globalThis`, especially for further reading on how unfortunately complicated the whole situation is.)
- cnity 5y agoGood catch!