function Person(name) {
this.name = name;
}
const person = new Person("Alice");
console.log(this.name); // 输出 "Alice"
const person1 = new Person("Alice");
const person2 = new Person("Bob");
console.log(person1.name); // 输出 "Alice"
console.log(person2.name); // 输出 "Bob"
console.log(that.name); // 错误,that没有指向任何对象
下一篇:that和this的区别和用法