Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: small cleanup of examples #263

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Nov 22, 2023

Use async/await in both examples. Use nullish coalescing.


Preview | Diff

Use async/await in both examples. Use nullish coalescing.
spec.bs Outdated Show resolved Hide resolved
PaymentRequest &&
PaymentRequest.isSecurePaymentConfirmationAvailable &&
await PaymentRequest.isSecurePaymentConfirmationAvailable();
await PaymentRequest?.isSecurePaymentConfirmationAvailable();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, I've never seen it before!

I think it's technically optional chaining (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) rather than nullish coalescing (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing), right?

Does this work as written if PaymentRequest itself is not defined? (As opposed to isSecurePaymentConfirmationAvailable not being defined). It seemed not when I tried it in Firefox, but I may have been holding it wrong. I had to do:

window.PaymentRequest?.isSecurePaymentConfirmationAvailable();

Without the window, I just got:

PaymentRequest?.isSecurePaymentConfirmationAvailable()
Uncaught ReferenceError: PaymentRequest is not defined
    <anonymous> debugger eval code:1
debugger eval code:1:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants