学习day1--class

33 阅读1分钟
1.类中默认使用局部严格模式
    #this指向该类实例对象
    例:
    class Person{
        constructor(name){
            this.name = name
        }
        study(){
            console.log(this)                          
        }
    }
    const p1 = new Person()
    p1.study()//this只想p1(实例对象)通过实例调用方法
    const x = p1.study
    x()//undefined 直接调用.因严格模式所以不只想window 而是undefined
    
    function aaa(){
        'use stric'
        console.log(this)//undefined
    }
    
![6081676647587_.pic.jpg](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2033840c269a418a896546dc672d43ac~tplv-k3u1fbpfcp-watermark.image?)