创建类
class Person {
constructor(name, age) {
this.name = name
this.age = age
}
study() {
console.log(this)
}
}
创建Person类的实例
let p1 = new Person('tom', 18)
通过实例调用类中的方法,这叫做实例调用
p1.study()
将类中的方法赋值给x,再调用x,这叫做直接调用
因为类中定义的方法,已经局部开启了严格模式,所以此处指向undefined
const x = p1.study
x() // undefined