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

Update function.md

This commit is contained in:
Huyue 2021-10-19 11:33:57 +08:00 committed by GitHub
parent de768691a7
commit 5b57360b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,10 +303,10 @@ function foo(x = x) {
// ... // ...
} }
foo() // ReferenceError: x is not defined foo() // ReferenceError: Cannot access 'x' before initialization
``` ```
上面代码中,参数`x = x`形成一个单独作用域。实际执行的是`let x = x`,由于暂时性死区的原因,这行代码会报错”x 未定义“ 上面代码中,参数`x = x`形成一个单独作用域。实际执行的是`let x = x`,由于暂时性死区的原因,这行代码会报错。
如果参数的默认值是一个函数,该函数的作用域也遵守这个规则。请看下面的例子。 如果参数的默认值是一个函数,该函数的作用域也遵守这个规则。请看下面的例子。