js重点

271 阅读1分钟

es6-11


    let
    const
    
    解构赋值
    模板字符串 `${}`
    对象简写
    箭头函数
    函数参数默认值
    
    
    ...扩展运算符 
    class
    promiss
    Map
    proxy
    
    async
    aweit
    
    import动态引入
    
    // 函数参数默认值
    function a(name="ya",age="19"){}
    
    let data= {
         a:1,
         b:2,
         c:3,
         d:4,
     }
     // 解构
    let { a, ...v } = data
    console.log(v)
    //{b: 2, c: 3, d: 4}
    
    ??"" // 判断undefined,null,'' 快捷方法
    console.log(undefined??"")
    //  ''
    console.log(null??"")
    // ''
    console.log(2??"")
    // 2
    console.log(true??"")
    // true

image.png

Event Loop

    js单线程
    微任务:promiss
    宏任务:js主体,setTimeOut,setInteval

内存管理机制

    新生代  复制->删除   超过25%-->老生代
    老生代  标记->清除->整理
    
    内存分区
    堆:引用类型 Object Array  先进先出
    栈:基本数据类型    先进后出
    池:const常量      
    

继承

    function Parent(name){
        this.name = name
    }
    function Child(name){
        this.name = name
    }

    
    // 原型链继承
    Child.prototype = new Parent()
    Child.prototype.constructor = Child
    
    缺点:多个子类实例指向同一个原型,修改会一起改
    
    // 构造函数继承
    function Child(){
        Parent.call(this,"小李")
    }
    
    缺点:只能继承父类内部方法属性,没法继承父类原型的属性
    
  
    // 组合模式
    function Child(){
        Parent.call(this,"小李")
    }
    Child.prototype = new Parent()
    Child.prototype.constructor = Child
    
    缺点:每次生成子类实例,就会多次执行父类构造函数
    
    // 寄生式继承
    Child.prototype = Parent.prototype
    Child.propotype.constructor = Child
    
    function Child(){
        Parent.call(this,"小王")
    }

image.png

    // 终极boss  寄生式组合继承
    Child.prototype = Object.create(Parent.prototype)
    Child.propotype.constructor = Child
    
    function Child(){
        Parent.call(this,"小王")
    }

原型图

蓝色线即为原型链

image.png

js是词法作用域不是动态作用域