Skip to content

Commit

Permalink
Merge pull request #606 from dplewis/subclass-user
Browse files Browse the repository at this point in the history
Example for extending Parse.User
  • Loading branch information
dplewis committed Mar 21, 2019
2 parents 05fe782 + 839c0c4 commit ef86547
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 30 additions & 0 deletions _includes/js/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ However, when using `extends`, the SDK is not automatically aware of your subcla
Parse.Object.registerSubclass('Monster', Monster);
```

Similarly, you can use `extends` with `Parse.User`.

```javascript
class CustomUser extends Parse.User {
constructor(attributes) {
super(attributes);
}

doSomething() {
return 5;
}
}
Parse.Object.registerSubclass('CustomUser', CustomUser);
```

In addition to queries, `logIn` and `signUp` will return the subclass `CustomUser`.

```javascript
const customUser = new CustomUser({ foo: 'bar' });
customUser.setUsername('username');
customUser.setPassword('password');
customUser.signUp().then((user) => {
// user is an instance of CustomUser
user.doSomething(); // return 5
user.get('foo'); // return 'bar'
});
```

`CustomUser.logIn` and `CustomUser.signUp` will return the subclass `CustomUser` (SDK v2.3.0).

## Saving Objects

Let's say you want to save the `GameScore` described above to the Parse Cloud. The interface is similar to a `Backbone.Model`, including the `save` method:
Expand Down
4 changes: 2 additions & 2 deletions assets/js/bundle.js

Large diffs are not rendered by default.

0 comments on commit ef86547

Please sign in to comment.