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

docs(let): 修正函数默认参数的死区问题

This commit is contained in:
兔哥 2016-05-04 14:02:22 +08:00
parent 6e8505bf8c
commit 71b13a4351
2 changed files with 3 additions and 3 deletions

View File

@ -133,7 +133,7 @@ function bar(x = y, y = 2) {
bar(); // 报错 bar(); // 报错
``` ```
上面代码中,调用`bar`函数之所以报错,是因为参数`x`默认值等于另一个参数`y`,而此时`y`还没有声明,属于”死区“。如果`y`的默认值是`x`,就不会报错,因为此时`x`已经声明了。 上面代码中,调用`bar`函数之所以报错(某些实现可能不报错),是因为参数`x`默认值等于另一个参数`y`,而此时`y`还没有声明,属于”死区“。如果`y`的默认值是`x`,就不会报错,因为此时`x`已经声明了。
```javascript ```javascript
function bar(x = 2, y = x) { function bar(x = 2, y = x) {

View File

@ -98,8 +98,8 @@ var s = '𠮷a';
for (let ch of s) { for (let ch of s) {
console.log(ch.codePointAt(0).toString(16)); console.log(ch.codePointAt(0).toString(16));
} }
// "20bb7" // 20bb7
// "" // 61
``` ```
`codePointAt`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。 `codePointAt`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。