JS1
This commit is contained in:
@@ -25,3 +25,11 @@
|
||||
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/12-this-keyword/starter.js)
|
||||
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/12-this-keyword/answer.js)
|
||||
|
||||
function a() {
|
||||
|
||||
}
|
||||
|
||||
const b = () => {
|
||||
|
||||
}
|
||||
@@ -4,15 +4,25 @@ const student = {
|
||||
sayHello() {
|
||||
// 任务:
|
||||
// 1. 用 this.name 输出问候语
|
||||
console.log(this.name + "你好!");
|
||||
|
||||
},
|
||||
createArrowReporter() {
|
||||
// 任务:
|
||||
// 2. 返回一个箭头函数
|
||||
// 3. 在箭头函数里输出 this.name
|
||||
return () => {
|
||||
console.log(this.name);
|
||||
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// 任务:
|
||||
// 4. 调用 student.sayHello()
|
||||
student.sayHello()
|
||||
// 5. 把 student.sayHello 赋值给 detachedHello 再调用
|
||||
const detachedHello = student.sayHello
|
||||
detachedHello()
|
||||
// 6. 调用 createArrowReporter 返回的新函数
|
||||
student.createArrowReporter()()
|
||||
|
||||
Reference in New Issue
Block a user