mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
docs(function): 调整不合适的函数描述
This commit is contained in:
parent
ee1b51ecd1
commit
d41bf835a1
@ -669,7 +669,7 @@ const square = n => n * n;
|
||||
箭头函数的一个用处是简化回调函数。
|
||||
|
||||
```javascript
|
||||
// 正常函数写法
|
||||
// 普通函数写法
|
||||
[1,2,3].map(function (x) {
|
||||
return x * x;
|
||||
});
|
||||
@ -681,7 +681,7 @@ const square = n => n * n;
|
||||
另一个例子是
|
||||
|
||||
```javascript
|
||||
// 正常函数写法
|
||||
// 普通函数写法
|
||||
var result = values.sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
@ -716,7 +716,7 @@ headAndTail(1, 2, 3, 4, 5)
|
||||
|
||||
(4)不可以使用`yield`命令,因此箭头函数不能用作 Generator 函数。
|
||||
|
||||
上面四点中,最重要的是第一点。对于普通函数来说,内部的`this`代表函数运行时所在的对象,但是这一点对箭头函数不成立。它没有自己的`this`对象,内部的`this`就是一个普通变量,指向定义时上层函数所在的对象。也就是说,箭头函数内部的`this`指向是固定的,相比之下,普通函数的`this`指向是可变的。
|
||||
上面四点中,最重要的是第一点。对于普通函数来说,内部的`this`指向函数运行时所在的对象,但是这一点对箭头函数不成立。它没有自己的`this`对象,内部的`this`就是定义时上层作用域中的`this`。也就是说,箭头函数内部的`this`指向是固定的,相比之下,普通函数的`this`指向是可变的。
|
||||
|
||||
```javascript
|
||||
function foo() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user