Skip to content

Commit

Permalink
edit function/length
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Nov 13, 2015
1 parent 0fc76fe commit 8afab8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ foo(undefined, null)
(function(a, b, c = 5){}).length // 2
```

上面代码中,`length`属性的返回值,等于函数的参数个数减去指定了默认值的参数个数。
上面代码中,`length`属性的返回值,等于函数的参数个数减去指定了默认值的参数个数。比如,上面最后一个函数,定义了3个参数,其中有一个参数`c`指定了默认值,因此`length`属性等于3减去1,最后得到2。

这是因为`length`属性的含义是,该函数预期传入的参数个数。某个参数指定默认值以后,预期传入的参数个数就不包括这个参数了。同理,rest参数也不会计入`length`属性。

```javascript
(function(...args) {}).length // 0
```

### 作用域

Expand Down
6 changes: 4 additions & 2 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

这对JavaScript语言很有必要。因为它的使用场景复杂,语法规则不统一,例外很多,各种运行环境的行为不一致,导致奇怪的语法问题层出不穷,任何语法书都不可能囊括所有情况。查看规格,不失为一种解决语法问题的最可靠、最权威的终极方法。

本节介绍如何读懂ECMAScript 6的规格文件。
本章介绍如何读懂ECMAScript 6的规格文件。

ECMAScript 6的规格,可以在ECMA国际标准组织的官方网站([www.ecma-international.org/ecma-262/6.0/](http:https://www.ecma-international.org/ecma-262/6.0/))免费下载和在线阅读。

Expand All @@ -20,7 +20,9 @@ ECMAScript 6规格的26章之中,第1章到第3章是对文件本身的介绍

## 相等运算符

先来看这个例子,请问下面表达式的值是多少。
相等运算符(`==`)是一个很让人头痛的运算符,它的语法行为多变,不符合直觉。这个小节就看看规格怎么规定它的行为。

请看下面这个表达式,请问它的值是多少。

```javascript
0 == null
Expand Down

0 comments on commit 8afab8c

Please sign in to comment.