Skip to content

Commit 076f2ca

Browse files
authored
Merge pull request ruanyf#551 from m4jing/patch-4
Updated example and explanation of Symbol.species
2 parents d808c68 + 3f28d7b commit 076f2ca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docs/symbol.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,14 @@ class MyArray extends Array {
591591
let a = new MyArray(1,2,3);
592592
let mapped = a.map(x => x * x);
593593

594+
a instanceof MyArray // true
595+
a instanceof Array // true
596+
594597
mapped instanceof MyArray // false
595598
mapped instanceof Array // true
596599
```
597600

598-
上面代码中,由于构造函数被替换成了`Array`。所以,`mapped`对象不是`MyArray`的实例,而是`Array`的实例
601+
上面代码中,`a``MyArray`的实例,所以`a instanceof MyArray`返回`true`由于构造函数被替换成了`Array`,所以`a`实际上也是`Array`的实例,于是`a instanceof Array`也返回`true`。而`mapped``Array.prototype.map`运算的结果,已经是真正的数组,它是`Array`的实例,而不是`MyArray`的实例,于是`mapped instanceof Array`返回`true`,而`mapped instanceof MyArray`返回`false`
599602

600603
### Symbol.match
601604

0 commit comments

Comments
 (0)