var who = { userName: '杜牧', age: 36, fun: function() { // 此时无法确定 this 指向 console.log(`我叫${ this.userName },今年${ this.age }岁。`); } }; // this 指向 who 对象 who.fun(); // 我叫杜牧,今年36岁。 var me = { userName: '李清照', age: 22 }; me.fun = who.fun; // this 指向 me 对象 me.fun(); // 我叫李清照,今年22岁。 var onWindow = who.fun; // 前面没有 点(.) // this 指向 window onWindow(); // 我叫undefined,今年undefined岁。
this -- 基础知识 (指向) - 07
关注
打赏