简体   繁体   English

Javascript匿名函数参数

[英]Javascript anonymous function parameters

i am just learning how to code javascript.我只是在学习如何编写 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.所有的PayPal JS SDK回调函数都有两个参数,数据和动作。 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:在单击按钮创建 PayPal 订单或订阅时,数据对象中没有任何用处,因此您不会找到使用它的示例——但如果您想在开发时检查其内容,可以将其记录到您的浏览器控制台,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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