解析函数声明Javascript

解析函数声明Javascript,javascript,parse-platform,Javascript,Parse Platform,我试图定义一个发送推送通知的云代码方法,但是我很难声明和调用这些方法。我需要一个方法来获取3个字符串参数跟踪、slug和channel,我知道如何用Java或其他OOP语言编写这些参数 私有void发送通知字符串跟踪、字符串段塞、字符串通道 调用sendNotificationsomeTracking、someSlug、someChannel 如何在Parse JS SDK中编写这些方法?您可以声明云代码函数,如Bjorn发布的指南中所述。为了在这种情况下帮助您,下面是一个方法定义的示例,它的行

我试图定义一个发送推送通知的云代码方法,但是我很难声明和调用这些方法。我需要一个方法来获取3个字符串参数跟踪、slug和channel,我知道如何用Java或其他OOP语言编写这些参数

私有void发送通知字符串跟踪、字符串段塞、字符串通道

调用sendNotificationsomeTracking、someSlug、someChannel


如何在Parse JS SDK中编写这些方法?

您可以声明云代码函数,如Bjorn发布的指南中所述。为了在这种情况下帮助您,下面是一个方法定义的示例,它的行为将与您所希望的一样

/**
 * Send Push Notification
 * Required:
 * tracking                          -- Tracking String
 * slug                              -- Slug String
 * channel                           -- Channel String
 */
Parse.Cloud.define("sendNotification", function(request, response) {
               // Obviously you don't need to assign these variables, but this is how you access the parameters passed in
               var tracking = request.params.tracking;
               var slug = request.params.slug;
               var channel = request.params.channel;
               // Send your push notification here, I'm not gonna write the whole thing for you! :)
                   // In the callback of your push notification call:
                   response.success();
                   // For a successful send and response.error() if it fails or an error occurs
               });
要在客户机中调用此方法,假设您使用java,因为您在问题语句中使用了java语法,您可以按照前面提到的云代码指南中概述的模式进行操作:

HashMap<String, Object> params = new HashMap<String, Object>();
params.put("tracking", "TRACKING_STRING");
params.put("slug", "SLUG_STRING");
params.put("channel", "CHANNEL_STRING");
ParseCloud.callFunctionInBackground("sendNotification", params, new FunctionCallback<Float>() {
   void done(ParseException e) {
       if (e == null) {
          // Your function was successful
       } else {
          // Your function failed, handle the error here
       }
   }
});

但是,如果您只是尝试从客户端发送推送通知,那么您可能应该使用此处概述的Parse内置函数:

您的问题是如何在JavaScript中定义函数?@ifrests基于标记,我想这是关于Parse框架的。Parse js SDK基于主干。也许你可以先看一下主干:一个普通的JavaScript函数就可以了。