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。");