mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
docs(let): ES6的块级作用域使得函数可以在条件作用域内声明
This commit is contained in:
+3
-8
@@ -887,13 +887,6 @@ function foo() {
|
||||
}
|
||||
|
||||
// ES5
|
||||
function foo() {
|
||||
setTimeout(function () {
|
||||
console.log("id:", this.id);
|
||||
}.bind(this), 100);
|
||||
}
|
||||
|
||||
// 或者
|
||||
function foo() {
|
||||
var _this = this;
|
||||
|
||||
@@ -903,6 +896,8 @@ function foo() {
|
||||
}
|
||||
```
|
||||
|
||||
上面代码中,箭头函数转成ES5代码时,内部的`this`需要改为引用外部的`this`。
|
||||
|
||||
请问下面的代码之中有几个`this`?
|
||||
|
||||
```javascript
|
||||
@@ -910,7 +905,7 @@ function foo() {
|
||||
return () => {
|
||||
return () => {
|
||||
return () => {
|
||||
console.log("id:", this.id);
|
||||
console.log(`id:`, this.id);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user