Files
charlie 877acb5a8f feat: Add JavaScript core exercises and solutions
- Implemented exercises for array high-order methods, memory and execution, switch statements, and final review.
- Added starter and answer files for each exercise to facilitate learning.
- Created a runner HTML file to execute JavaScript code and display console outputs.
- Updated README files to include exercise objectives, tasks, and usage instructions.
2026-03-13 11:09:19 +08:00

27 lines
869 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const student = {
name: "林晨",
stage: "JavaScript 核心",
sayHello() {
const currentName = this && this.name ? this.name : "未知调用者";
const currentStage = this && this.stage ? this.stage : "未知阶段";
console.log(`你好,我是 ${currentName},正在学习 ${currentStage}`);
},
createArrowReporter() {
return () => {
console.log(`箭头函数继承到的 this.name${this.name}`);
};
},
};
student.sayHello();
const detachedHello = student.sayHello;
detachedHello();
const arrowReporter = student.createArrowReporter();
arrowReporter();
console.log("对象方法里的 this 通常指向调用它的对象。");
console.log("脱离对象单独调用后,普通函数里的 this 会跟着调用方式变化。");
console.log("箭头函数没有自己的 this它会继承创建它时外层的 this。");