Skip to content

Commit 05ab709

Browse files
committed
replace var
1 parent e39d3f2 commit 05ab709

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

docs/src/rules/object-shorthand.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Here are a few common examples using the ES5 syntax:
1616

1717
```js
1818
// properties
19-
var foo = {
19+
const foo = {
2020
x: x,
2121
y: y,
2222
z: z,
2323
};
2424

2525
// methods
26-
var foo = {
26+
const foo = {
2727
a: function() {},
2828
b: function() {}
2929
};
@@ -33,10 +33,10 @@ Now here are ES6 equivalents:
3333

3434
```js
3535
// properties
36-
var foo = {x, y, z};
36+
const foo = {x, y, z};
3737

3838
// methods
39-
var foo = {
39+
const foo = {
4040
a() {},
4141
b() {}
4242
};
@@ -53,7 +53,7 @@ Each of the following properties would warn:
5353
```js
5454
/*eslint object-shorthand: "error"*/
5555

56-
var foo = {
56+
const foo = {
5757
w: function() {},
5858
x: function *() {},
5959
[y]: function() {},
@@ -66,7 +66,7 @@ In that case the expected syntax would have been:
6666
```js
6767
/*eslint object-shorthand: "error"*/
6868

69-
var foo = {
69+
const foo = {
7070
w() {},
7171
*x() {},
7272
[y]() {},
@@ -80,7 +80,7 @@ The following will *not* warn:
8080
```js
8181
/*eslint object-shorthand: "error"*/
8282

83-
var foo = {
83+
const foo = {
8484
x: (y) => y
8585
};
8686
```
@@ -126,7 +126,7 @@ Example of **incorrect** code for this rule with the `"always", { "avoidQuotes":
126126
```js
127127
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
128128

129-
var foo = {
129+
const foo = {
130130
"bar-baz"() {}
131131
};
132132
```
@@ -140,7 +140,7 @@ Example of **correct** code for this rule with the `"always", { "avoidQuotes": t
140140
```js
141141
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
142142

143-
var foo = {
143+
const foo = {
144144
"bar-baz": function() {},
145145
"qux": qux
146146
};
@@ -163,7 +163,7 @@ Example of **correct** code for this rule with the `"always", { "ignoreConstruct
163163
```js
164164
/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
165165

166-
var foo = {
166+
const foo = {
167167
ConstructorFunction: function() {}
168168
};
169169
```
@@ -179,7 +179,7 @@ Example of **correct** code for this rule with the `"always", { "methodsIgnorePa
179179
```js
180180
/*eslint object-shorthand: ["error", "always", { "methodsIgnorePattern": "^bar$" }]*/
181181

182-
var foo = {
182+
const foo = {
183183
bar: function() {}
184184
};
185185
```
@@ -201,7 +201,7 @@ Example of **incorrect** code for this rule with the `"always", { "avoidExplicit
201201
```js
202202
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
203203

204-
var foo = {
204+
const foo = {
205205
foo: (bar, baz) => {
206206
return bar + baz;
207207
},
@@ -221,7 +221,7 @@ Example of **correct** code for this rule with the `"always", { "avoidExplicitRe
221221
```js
222222
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
223223

224-
var foo = {
224+
const foo = {
225225
foo(bar, baz) {
226226
return bar + baz;
227227
},
@@ -239,7 +239,7 @@ Example of **incorrect** code for this rule with the `"consistent"` option:
239239
```js
240240
/*eslint object-shorthand: [2, "consistent"]*/
241241

242-
var foo = {
242+
const foo = {
243243
a,
244244
b: "foo",
245245
};
@@ -254,12 +254,12 @@ Examples of **correct** code for this rule with the `"consistent"` option:
254254
```js
255255
/*eslint object-shorthand: [2, "consistent"]*/
256256

257-
var foo = {
257+
const foo = {
258258
a: a,
259259
b: "foo"
260260
};
261261

262-
var bar = {
262+
const bar = {
263263
a,
264264
b,
265265
};
@@ -274,7 +274,7 @@ Example of **incorrect** code with the `"consistent-as-needed"` option, which is
274274
```js
275275
/*eslint object-shorthand: [2, "consistent-as-needed"]*/
276276

277-
var foo = {
277+
const foo = {
278278
a: a,
279279
b: b,
280280
};

docs/src/rules/prefer-promise-reject-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ new Promise(function(resolve, reject) {
6060
reject(new Error("something bad happened"));
6161
});
6262

63-
var foo = getUnknownValue();
63+
const foo = getUnknownValue();
6464
Promise.reject(foo);
6565
```
6666

docs/src/rules/prefer-rest-params.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ function foo() {
2929
}
3030

3131
function foo(action) {
32-
var args = Array.prototype.slice.call(arguments, 1);
32+
const args = Array.prototype.slice.call(arguments, 1);
3333
action.apply(null, args);
3434
}
3535

3636
function foo(action) {
37-
var args = [].slice.call(arguments, 1);
37+
const args = [].slice.call(arguments, 1);
3838
action.apply(null, args);
3939
}
4040
```
@@ -61,7 +61,7 @@ function foo(arguments) {
6161
console.log(arguments); // This is the first argument.
6262
}
6363
function foo() {
64-
var arguments = 0;
64+
const arguments = 0;
6565
console.log(arguments); // This is a local variable.
6666
}
6767
```

docs/src/rules/prefer-spread.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ related_rules:
99
Before ES2015, one must use `Function.prototype.apply()` to call variadic functions.
1010

1111
```js
12-
var args = [1, 2, 3, 4];
12+
const args = [1, 2, 3, 4];
1313
Math.max.apply(Math, args);
1414
```
1515

1616
In ES2015, one can use spread syntax to call variadic functions.
1717

1818
```js
19-
var args = [1, 2, 3, 4];
19+
const args = [1, 2, 3, 4];
2020
Math.max(...args);
2121
```
2222

docs/src/rules/prefer-template.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ related_rules:
1111
In ES2015 (ES6), we can use template literals instead of string concatenation.
1212

1313
```js
14-
var str = "Hello, " + name + "!";
14+
const str = "Hello, " + name + "!";
1515
```
1616

1717
```js
18-
var str = `Hello, ${name}!`;
18+
const str = `Hello, ${name}!`;
1919
```
2020

2121
## Rule Details
@@ -31,8 +31,8 @@ Examples of **incorrect** code for this rule:
3131
```js
3232
/*eslint prefer-template: "error"*/
3333

34-
var str = "Hello, " + name + "!";
35-
var str = "Time: " + (12 * 60 * 60 * 1000);
34+
const str = "Hello, " + name + "!";
35+
const str1 = "Time: " + (12 * 60 * 60 * 1000);
3636
```
3737

3838
:::
@@ -44,12 +44,12 @@ Examples of **correct** code for this rule:
4444
```js
4545
/*eslint prefer-template: "error"*/
4646

47-
var str = "Hello World!";
48-
var str = `Hello, ${name}!`;
49-
var str = `Time: ${12 * 60 * 60 * 1000}`;
47+
const str = "Hello World!";
48+
const str1 = `Hello, ${name}!`;
49+
const str2 = `Time: ${12 * 60 * 60 * 1000}`;
5050

5151
// This is reported by `no-useless-concat`.
52-
var str = "Hello, " + "World!";
52+
const str4 = "Hello, " + "World!";
5353
```
5454

5555
:::

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy