Skip to content

Commit

Permalink
Merge branch 'gh-pages' of github.com:ruanyf/es6tutorial into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Dec 5, 2017
2 parents 075c27b + 076f2ca commit 7740f5d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/symbol.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,14 @@ class MyArray extends Array {
let a = new MyArray(1,2,3);
let mapped = a.map(x => x * x);

a instanceof MyArray // true
a instanceof Array // true

mapped instanceof MyArray // false
mapped instanceof Array // true
```

上面代码中,由于构造函数被替换成了`Array`。所以,`mapped`对象不是`MyArray`的实例,而是`Array`的实例
上面代码中,`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`

### Symbol.match

Expand Down

0 comments on commit 7740f5d

Please sign in to comment.