Skip to content

Commit 52e01b1

Browse files
authored
Replace var to const (#795)
1 parent 6e2a85a commit 52e01b1

10 files changed

+159
-159
lines changed

_includes/js/analytics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Without having to implement any client-side logic, you can view real-time graphs
1414
Say your app offers search functionality for apartment listings, and you want to track how often the feature is used, with some additional metadata.
1515

1616
```javascript
17-
var dimensions = {
17+
const dimensions = {
1818
// Define ranges to bucket data points into meaningful segments
1919
priceRange: '1000-1500',
2020
// Did the user filter the query?
@@ -29,7 +29,7 @@ Parse.Analytics.track('search', dimensions);
2929
`Parse.Analytics` can even be used as a lightweight error tracker — simply invoke the following and you'll have access to an overview of the rate and frequency of errors, broken down by error code, in your application:
3030

3131
```javascript
32-
var codeString = '' + error.code;
32+
const codeString = '' + error.code;
3333
Parse.Analytics.track('error', { code: codeString });
3434
```
3535

_includes/js/files.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
Getting started with `Parse.File` is easy. There are a couple of ways to create a file. The first is with a base64-encoded String.
88

99
```javascript
10-
var base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
11-
var file = new Parse.File("myfile.txt", { base64: base64 });
10+
const base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
11+
const file = new Parse.File("myfile.txt", { base64: base64 });
1212
```
1313

1414
Alternatively, you can create a file from an array of byte values:
1515

1616
```javascript
17-
var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
18-
var file = new Parse.File("myfile.txt", bytes);
17+
const bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
18+
const file = new Parse.File("myfile.txt", bytes);
1919
```
2020

2121
Parse will auto-detect the type of file you are uploading based on the file extension, but you can specify the `Content-Type` with a third parameter:
2222

2323
```javascript
24-
var file = new Parse.File("myfile.zzz", fileData, "image/png");
24+
const file = new Parse.File("myfile.zzz", fileData, "image/png");
2525
```
2626

2727
### Client Side
@@ -34,12 +34,12 @@ In a browser, you'll want to use an html form with a file upload control. To do
3434
Then, in a click handler or other function, get a reference to that file:
3535

3636
```javascript
37-
var fileUploadControl = $("#profilePhotoFileUpload")[0];
37+
const fileUploadControl = $("#profilePhotoFileUpload")[0];
3838
if (fileUploadControl.files.length > 0) {
39-
var file = fileUploadControl.files[0];
40-
var name = "photo.jpg";
39+
const file = fileUploadControl.files[0];
40+
const name = "photo.jpg";
4141

42-
var parseFile = new Parse.File(name, file);
42+
const parseFile = new Parse.File(name, file);
4343
}
4444
```
4545

@@ -88,7 +88,7 @@ request(options)
8888
Finally, after the save completes, you can associate a `Parse.File` with a `Parse.Object` just like any other piece of data:
8989

9090
```javascript
91-
var jobApplication = new Parse.Object("JobApplication");
91+
const jobApplication = new Parse.Object("JobApplication");
9292
jobApplication.set("applicantName", "Joe Smith");
9393
jobApplication.set("applicantResumeFile", parseFile);
9494
jobApplication.save();
@@ -99,7 +99,7 @@ jobApplication.save();
9999
How to best retrieve the file contents back depends on the context of your application. Because of cross-domain request issues, it's best if you can make the browser do the work for you. Typically, that means rendering the file's URL into the DOM. Here we render an uploaded profile photo on a page with jQuery:
100100

101101
```javascript
102-
var profilePhoto = profile.get("photoFile");
102+
const profilePhoto = profile.get("photoFile");
103103
$("profileImg")[0].src = profilePhoto.url();
104104
```
105105

_includes/js/geopoints.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Parse allows you to associate real-world latitude and longitude coordinates with
77
To associate a point with an object you first need to create a `Parse.GeoPoint`. For example, to create a point with latitude of 40.0 degrees and -30.0 degrees longitude:
88

99
```javascript
10-
var point = new Parse.GeoPoint({latitude: 40.0, longitude: -30.0});
10+
const point = new Parse.GeoPoint({latitude: 40.0, longitude: -30.0});
1111
```
1212

1313
This point is then stored in the object as a regular field.
@@ -67,10 +67,10 @@ const pizzaPlacesInSF = query.find();
6767
It's also possible to query for the set of objects that are contained within a particular area. To find the objects in a rectangular bounding box, add the `withinGeoBox` restriction to your `Parse.Query`.
6868

6969
```javascript
70-
var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
71-
var northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);
70+
const southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
71+
const northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);
7272

73-
var query = new Parse.Query(PizzaPlaceObject);
73+
const query = new Parse.Query(PizzaPlaceObject);
7474
query.withinGeoBox("location", southwestOfSF, northeastOfSF);
7575
const pizzaPlacesInSF = await query.find();
7676
```

_includes/js/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ The JavaScript ecosystem is wide and incorporates a large number of platforms an
88
To use the npm modules for a browser based application, include it as you normally would:
99

1010
```js
11-
var Parse = require('parse');
11+
const Parse = require('parse');
1212
```
1313

1414
For server-side applications or Node.js command line tools, include `'parse/node'`:
1515

1616
```js
1717
// In a node.js environment
18-
var Parse = require('parse/node');
18+
const Parse = require('parse/node');
1919
// ES6 Minimized
2020
import Parse from 'parse/dist/parse.min.js';
2121
```
2222

2323
For React Native applications, include `'parse/react-native.js'`:
2424
```js
2525
// In a React Native application
26-
var Parse = require('parse/react-native.js');
26+
const Parse = require('parse/react-native.js');
2727
```
2828

2929
Additionally on React-Native / Expo environments, make sure to add the piece of code below :

_includes/js/objects.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ To create a new subclass, use the `Parse.Object.extend` method. Any `Parse.Quer
1818

1919
```javascript
2020
// Simple syntax to create a new subclass of Parse.Object.
21-
var GameScore = Parse.Object.extend("GameScore");
21+
const GameScore = Parse.Object.extend("GameScore");
2222

2323
// Create a new instance of that class.
24-
var gameScore = new GameScore();
24+
const gameScore = new GameScore();
2525

2626
// Alternatively, you can use the typical Backbone syntax.
27-
var Achievement = Parse.Object.extend({
27+
const Achievement = Parse.Object.extend({
2828
className: "Achievement"
2929
});
3030
```
@@ -34,7 +34,7 @@ You can add additional methods and properties to your subclasses of `Parse.Objec
3434
```javascript
3535

3636
// A complex subclass of Parse.Object
37-
var Monster = Parse.Object.extend("Monster", {
37+
const Monster = Parse.Object.extend("Monster", {
3838
// Instance methods
3939
hasSuperHumanStrength: function () {
4040
return this.get("strength") > 18;
@@ -46,13 +46,13 @@ var Monster = Parse.Object.extend("Monster", {
4646
}, {
4747
// Class methods
4848
spawn: function(strength) {
49-
var monster = new Monster();
49+
const monster = new Monster();
5050
monster.set("strength", strength);
5151
return monster;
5252
}
5353
});
5454

55-
var monster = Monster.spawn(200);
55+
const monster = Monster.spawn(200);
5656
alert(monster.get('strength')); // Displays 200.
5757
alert(monster.sound); // Displays Rawr.
5858
```
@@ -75,7 +75,7 @@ class Monster extends Parse.Object {
7575
}
7676

7777
static spawn(strength) {
78-
var monster = new Monster();
78+
const monster = new Monster();
7979
monster.set('strength', strength);
8080
return monster;
8181
}
@@ -156,8 +156,8 @@ There are also a few fields you don't need to specify that are provided as a con
156156
If you prefer, you can set attributes directly in your call to `save` instead.
157157

158158
```javascript
159-
var GameScore = Parse.Object.extend("GameScore");
160-
var gameScore = new GameScore();
159+
const GameScore = Parse.Object.extend("GameScore");
160+
const gameScore = new GameScore();
161161

162162
gameScore.save({
163163
score: 1337,
@@ -176,22 +176,22 @@ gameScore.save({
176176
You may add a `Parse.Object` as the value of a property in another `Parse.Object`. By default, when you call `save()` on the parent object, all nested objects will be created and/or saved as well in a batch operation. This feature makes it really easy to manage relational data as you don't have to take care of creating the objects in any specific order.
177177

178178
```javascript
179-
var Child = Parse.Object.extend("Child");
180-
var child = new Child();
179+
const Child = Parse.Object.extend("Child");
180+
const child = new Child();
181181

182-
var Parent = Parse.Object.extend("Parent");
183-
var parent = new Parent();
182+
const Parent = Parse.Object.extend("Parent");
183+
const parent = new Parent();
184184

185-
parent.save({child: child});
185+
parent.save({ child: child });
186186
// Automatically the object Child is created on the server
187187
// just before saving the Parent
188188
```
189189

190190
In some scenarios, you may want to prevent this default chain save. For example, when saving a team member's profile that points to an account owned by another user to which you don't have write access. In this case, setting the option `cascadeSave` to `false` may be useful:
191191

192192
```javascript
193-
var TeamMember = Parse.Object.extend("TeamMember");
194-
var teamMember = new TeamMember();
193+
const TeamMember = Parse.Object.extend("TeamMember");
194+
const teamMember = new TeamMember();
195195
teamMember.set('ownerAccount', ownerAccount); // Suppose `ownerAccount` has been created earlier.
196196

197197
teamMember.save(null, { cascadeSave: false });
@@ -206,22 +206,22 @@ teamMember.save(null, { cascadeSave: false });
206206
You may pass a `context` dictionary that is accessible in Cloud Code `beforeSave` and `afterSave` triggers for that `Parse.Object`. This is useful if you want to condition certain operations in Cloud Code triggers on ephemeral information that should not be saved with the `Parse.Object` in the database. The context is ephemeral in the sense that it vanishes after the Cloud Code triggers for that particular `Parse.Object` have executed. For example:
207207

208208
```javascript
209-
var TeamMember = Parse.Object.extend("TeamMember");
210-
var teamMember = new TeamMember();
209+
const TeamMember = Parse.Object.extend("TeamMember");
210+
const teamMember = new TeamMember();
211211
teamMember.set("team", "A");
212212

213-
var context = { notifyTeam: false };
213+
const context = { notifyTeam: false };
214214
await teamMember.save(null, { context: context });
215215
```
216216

217217
The context is then accessible in Cloud Code:
218218

219219
```javascript
220220
Parse.Cloud.afterSave("TeamMember", async (req) => {
221-
var notifyTeam = req.context.notifyTeam;
222-
if (notifyTeam) {
223-
// Notify team about new member.
224-
}
221+
const notifyTeam = req.context.notifyTeam;
222+
if (notifyTeam) {
223+
// Notify team about new member.
224+
}
225225
});
226226
```
227227

@@ -230,8 +230,8 @@ Parse.Cloud.afterSave("TeamMember", async (req) => {
230230
Saving data to the cloud is fun, but it's even more fun to get that data out again. If the `Parse.Object` has been uploaded to the server, you can use the `objectId` to get it using a `Parse.Query`:
231231

232232
```javascript
233-
var GameScore = Parse.Object.extend("GameScore");
234-
var query = new Parse.Query(GameScore);
233+
const GameScore = Parse.Object.extend("GameScore");
234+
const query = new Parse.Query(GameScore);
235235
query.get("xWMyZ4YEGZ")
236236
.then((gameScore) => {
237237
// The object was retrieved successfully.
@@ -244,9 +244,9 @@ query.get("xWMyZ4YEGZ")
244244
To get the values out of the `Parse.Object`, use the `get` method.
245245

246246
```javascript
247-
var score = gameScore.get("score");
248-
var playerName = gameScore.get("playerName");
249-
var cheatMode = gameScore.get("cheatMode");
247+
const score = gameScore.get("score");
248+
const playerName = gameScore.get("playerName");
249+
const cheatMode = gameScore.get("cheatMode");
250250
```
251251

252252
Alternatively, the `attributes` property of the `Parse.Object` can be treated as a Javascript object, and even destructured.
@@ -258,10 +258,10 @@ const { score, playerName, cheatMode } = result.attributes;
258258
The four special reserved values are provided as properties and cannot be retrieved using the 'get' method nor modified with the 'set' method:
259259

260260
```javascript
261-
var objectId = gameScore.id;
262-
var updatedAt = gameScore.updatedAt;
263-
var createdAt = gameScore.createdAt;
264-
var acl = gameScore.getACL();
261+
const objectId = gameScore.id;
262+
const updatedAt = gameScore.updatedAt;
263+
const createdAt = gameScore.createdAt;
264+
const acl = gameScore.getACL();
265265
```
266266

267267
If you need to refresh an object you already have with the latest data that
@@ -290,8 +290,8 @@ Updating an object is simple. Just set some new data on it and call the save met
290290

291291
```javascript
292292
// Create the object.
293-
var GameScore = Parse.Object.extend("GameScore");
294-
var gameScore = new GameScore();
293+
const GameScore = Parse.Object.extend("GameScore");
294+
const gameScore = new GameScore();
295295

296296
gameScore.set("score", 1337);
297297
gameScore.set("playerName", "Sean Plott");
@@ -378,16 +378,16 @@ To create a new `Post` with a single `Comment`, you could write:
378378

379379
```javascript
380380
// Declare the types.
381-
var Post = Parse.Object.extend("Post");
382-
var Comment = Parse.Object.extend("Comment");
381+
const Post = Parse.Object.extend("Post");
382+
const Comment = Parse.Object.extend("Comment");
383383

384384
// Create the post
385-
var myPost = new Post();
385+
const myPost = new Post();
386386
myPost.set("title", "I'm Hungry");
387387
myPost.set("content", "Where should we go for lunch?");
388388

389389
// Create the comment
390-
var myComment = new Comment();
390+
const myComment = new Comment();
391391
myComment.set("content", "Let's do Sushirrito.");
392392

393393
// Add the post as a value in the comment
@@ -400,7 +400,7 @@ myComment.save();
400400
Internally, the Parse framework will store the referred-to object in just one place, to maintain consistency. You can also link objects using just their `objectId`s like so:
401401

402402
```javascript
403-
var post = new Post();
403+
const post = new Post();
404404
post.id = "1zEcyElZ80";
405405

406406
myComment.set("parent", post);
@@ -419,8 +419,8 @@ const title = post.get("title");
419419
Many-to-many relationships are modeled using `Parse.Relation`. This works similar to storing an array of `Parse.Object`s in a key, except that you don't need to fetch all of the objects in a relation at once. In addition, this allows `Parse.Relation` to scale to many more objects than the array of `Parse.Object` approach. For example, a `User` may have many `Posts` that she might like. In this case, you can store the set of `Posts` that a `User` likes using `relation`. In order to add a `Post` to the "likes" list of the `User`, you can do:
420420

421421
```javascript
422-
var user = Parse.User.current();
423-
var relation = user.relation("likes");
422+
const user = Parse.User.current();
423+
const relation = user.relation("likes");
424424
relation.add(post);
425425
user.save();
426426
```
@@ -460,7 +460,7 @@ relation.query().find({
460460
If you want only a subset of the Posts, you can add extra constraints to the `Parse.Query` returned by query like this:
461461

462462
```javascript
463-
var query = relation.query();
463+
const query = relation.query();
464464
query.equalTo("title", "I'm Hungry");
465465
query.find({
466466
success:function(list) {
@@ -489,16 +489,16 @@ So far we've used values with type `String`, `Number`, and `Parse.Object`. Parse
489489
Some examples:
490490

491491
```javascript
492-
var number = 42;
493-
var bool = false;
494-
var string = "the number is " + number;
495-
var date = new Date();
496-
var array = [string, number];
497-
var object = { number: number, string: string };
498-
var pointer = MyClassName.createWithoutData(objectId);
492+
const number = 42;
493+
const bool = false;
494+
const string = "the number is " + number;
495+
const date = new Date();
496+
const array = [string, number];
497+
const object = { number: number, string: string };
498+
const pointer = MyClassName.createWithoutData(objectId);
499499

500-
var BigObject = Parse.Object.extend("BigObject");
501-
var bigObject = new BigObject();
500+
const BigObject = Parse.Object.extend("BigObject");
501+
const bigObject = new BigObject();
502502
bigObject.set("myNumber", number);
503503
bigObject.set("myBool", bool);
504504
bigObject.set("myString", string);

0 commit comments

Comments
 (0)