Skip to content

Parse.com Javascript Guide

josher19 edited this page Jun 18, 2012 · 2 revisions

The Parse.com Javascript Guide is pretty good, but it looks like the Sample Code in the documentation needs to be updated and revised. I went through the example code and found these errors (sorted by section).

Parse.Object

var monster = Monster.spawn(200);
alert(monster.strength());  // Displays 200.

should be:

var monster = new Monster().spawn(200);
alert(monster.get("strength"));  // Displays 200.

Relational Data

var user = Parse.User.currentUser();

should be

var user = Parse.User.current();

In the nearby text "For example, a User may have many Posts" Should hyperlink the word "User" to #users because they will need to do a user.signUp before this code will work.

Updating Objects

gameScore.increment is not defined.

Need to defined something along the lines of:

increment = function (attr) { var newval = parseFloat(this.get(attr)) + 1; this.set(attr, newval); return newval; }

but with more error handling.

Also, user.save() will not work, requires a callback:

user.save(null, {
  success : function (obj) {
    // The object was retrieved successfully.
    last = obj;
    $('.error').hide();
    $('.success').fadeOut().fadeIn().text(JSON.stringify(obj)); 
  },
  error : function (obj, error) {
    $('.success').hide();
    $('.error').show().text(JSON.stringify(obj) + " // " + JSON.stringify(error));
    // The object was not retrieved successfully.
    // error is a Parse.Error with an error code and description.
  }
});

Relational Queries

In example code,

query.doesNotMatchesQuery

should be

query.doesNotMatchQuery

Modifying a Collection

collection.add([
   {"name", "Duke"},
   {"name", "Scarlett"}
]);

should be:

collection.add([
  {"name": "Duke"},
  {"name": "Scarlett"}
]);

and

collection.reset([
  {"name", "Hawk"},
  {"name", "Jane"}
]);

should be:

collection.reset([
  {"name": "Hawk"},
  {"name": "Jane"}
]);

Security For Other Objects

privateNote.setACL(new Parse.ACL(Parse.User.current());

should be

privateNote.setACL(new Parse.ACL(Parse.User.current()));

Error Handling

error: function(error)

// should be

error: function(results, error)

Final hyperlink in document points to https://parse.com/docs/ss when it should point to https://parse.com/docs/js