函数怎么调用决定了 this 是谁!这可是 JS 中最令人头秃的问题之一。
哈哈哈!我要把 this 指向全局 window,或者 undefined,让你找不到对象!👻
我有三大神器来锁定 this:
我们要借用 person 对象的方法,但是用在 hero 对象上!
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const hero = {
firstName: "Iron",
lastName: "Man"
}