This commit is contained in:
rou
2026-03-19 15:17:29 +08:00
parent 81004b437c
commit 3afbee1535
14 changed files with 190 additions and 6 deletions

View File

@@ -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 = () => {
}

View File

@@ -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()()