Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

Var undefined in closure

$
0
0

I'm working on upgrading Stripe on an old project to use Stripe Elements but I'm having a JS scope issue where createPaymentMethod is receiving undefined rather than the element instance. I've tied switching () => {} closure syntax but I'm not having any luck.

$(document).ready(function () {
    const card = elements.create('card');
    card.mount('#card-element');

    // Other elements in this file rely on jquery, I'm not using jquery here because the stripe examples don't use them
    var form = document.getElementById('payment-form');
    form.addEventListener('submit', function(event) {
        event.preventDefault();

        // "card" is undefined here
        stripe.createPaymentMethod(card).then(function(result) {
            // do stuff
        });
    });
});

Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>