简体   繁体   中英

Javascript anonymous function parameters

i am just learning how to code javascript. got confused by this chunk of code. from my reading function(data, actions) is an anonymous function that passes two parameters to the function body. however, i don't see "data" being referenced anywhere inside the function. am i reading it wrong?

<script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      // Set up the transaction
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    }
  }).render('#paypal-button-container');
</script>

All the PayPal JS SDK callback functions have two parameters, data and actions. This is just a convention used.

When creating a PayPal order or subscription on button click there isn't anything useful in the data object, so you won't find samples that make use of it -- but if you wanted to check its contents while developing you can log it to your browser console with something like:

        createOrder: function(data, actions) {
            console.log("createOrder data", data, JSON.stringify(data,null,2) );
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: '0.01'
                    }
                }]
            });
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM