1

My question is about the first line of parse cloud function. for example, this function is copy from parse docs:

Parse.Cloud.beforeSave(Parse.User, function(request, response) { 
   if (!request.object.get("email")) {
   response.error("email is required for signup");
   } else {
   response.success();
  }
});

The Parse.User is a parse predefined class. Does that mean this cloud function will be automatically executed when saving a object in this class?

Another question is also about the class. here are two examples of parse cloud function from parse example app Anypic and Parse docs:

 Parse.Cloud.beforeSave('Activity', function(request, response) {
   var currentUser = request.user;
   var objectUser = request.object.get('fromUser');
   if(!currentUser || !objectUser) {
   response.error('An Activity should have a valid fromUser.');
  } else if (currentUser.id === objectUser.id) {
   response.success();
  } else {
   response.error('Cannot set fromUser on Activity to a user other than the current user.');
  }
});


  Parse.Cloud.beforeSave("Review", function(request, response) {
    if (request.object.get("stars") < 1) {
    response.error("you cannot give less than one star");
    } else if (request.object.get("stars") > 5) {
     response.error("you cannot give more than five stars");
    } else {
    response.success();
  }
});

What's the difference between these two cloud function in the first line: the Activity is quoted in single quotation marks but the Review is quoted in double quotation marks. Are they all stands for some parse subclass or something else?

1 Answers1

0

To answer your original question: Yes, the function with signature:

Parse.Cloud.beforeSave(Parse.User, function(request, response)

will be executed before every Parse.User class object is saved.

To answer your next question, those two examples are equivalent.

http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript

They do pre-save stuff for the Activity and Review classes respectively.

BHendricks
  • 4,423
  • 6
  • 32
  • 59
  • Thanks for the link. So it means i can use either double or single quotation marks to define a parse subclass. Is my understanding right? – Victor Cooper Sep 03 '14 at 01:04