1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 18:32:22 +00:00

Merge pull request #375 from longhuicode/patch-2

outer 输出位置表述有误
This commit is contained in:
Ruan YiFeng 2017-04-14 13:01:03 +08:00 committed by GitHub
commit 2bf5a3ec09

View File

@ -301,10 +301,10 @@ let foo = 'outer';
function bar(func = x => foo) {
let foo = 'inner';
console.log(func()); // outer
console.log(func());
}
bar();
bar(); // outer
```
上面代码中,函数`bar`的参数`func`的默认值是一个匿名函数,返回值为变量`foo`。函数参数形成的单独作用域里面,并没有定义变量`foo`,所以`foo`指向外层的全局变量`foo`,因此输出`outer`