mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-27 20:32:21 +00:00
bar()输出表述有误
bar() 输出表述有误, outer 应该在 bar() 运行时输出!
This commit is contained in:
parent
ed9c9c1327
commit
b330d721ac
@ -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`。
|
||||
|
Loading…
x
Reference in New Issue
Block a user