Skip to content

Commit 9b169be

Browse files
committed
docs(symbol): fix some error
1 parent 4e2fadc commit 9b169be

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

docs/symbol.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class MyClass {
392392
}
393393
}
394394

395-
[1, 2, 3] instanceof MyClass() // true
395+
[1, 2, 3] instanceof new MyClass() // true
396396
```
397397

398398
### Symbol.isConcatSpreadable
@@ -420,17 +420,19 @@ obj[Symbol.isConcatSpreadable] = true;
420420
['a', 'b'].concat(obj, 'e') // ['a', 'b', 'c', 'd', 'e']
421421
```
422422

423-
对于一个类来说,`Symbol.isConcatSpreadable`属性必须写成一个返回布尔值的方法
423+
对于一个类来说,`Symbol.isConcatSpreadable`属性必须写成实例的属性
424424

425425
```javascript
426426
class A1 extends Array {
427-
[Symbol.isConcatSpreadable]() {
428-
return true;
427+
constructor(args) {
428+
super(args);
429+
this[Symbol.isConcatSpreadable] = true;
429430
}
430431
}
431432
class A2 extends Array {
432-
[Symbol.isConcatSpreadable]() {
433-
return false;
433+
constructor(args) {
434+
super(args);
435+
this[Symbol.isConcatSpreadable] = false;
434436
}
435437
}
436438
let a1 = new A1();
@@ -443,7 +445,7 @@ a2[1] = 6;
443445
// [1, 2, 3, 4, [5, 6]]
444446
```
445447

446-
上面代码中,类`A1`是可扩展的,类`A2`是不可扩展的,所以使用`concat`时有不一样的结果。
448+
上面代码中,类`A1`是可展开的,类`A2`是不可展开的,所以使用`concat`时有不一样的结果。
447449

448450
### Symbol.species
449451

@@ -582,7 +584,7 @@ let obj = {
582584

583585
2 * obj // 246
584586
3 + obj // '3default'
585-
obj === 'default' // true
587+
obj == 'default' // true
586588
String(obj) // 'str'
587589
```
588590

0 commit comments

Comments
 (0)