Skip to content

Example for extending Parse.User #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.