欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Daily summary

程序员文章站 2022-05-05 23:13:08
...

ES6 Part

const

const 声明的对象改变其属性值,是可以的,因为内存地址没变。

如果要使其对象的属性不能改变,使用 Object.defineProperty 设置不可写,也可使用Object.freeze()进行冻结。

如果冻结嵌套对象可以自定义递归冻结函数。

    function myFreeze(obj) {
        Object.freeze(obj)
        Object.keys(obj).forEach((key) => {
            if (typeof obj[key] === 'object' && typeof obj[key] != null) {
                myFreeze(obj[key])
            }
        })
    }

解构

使用场景

  • 函数传参
    function sum([a,b,c]){
        return a+b+c
    }
    a([1,2,3])
  • 函数返回值
    function sum(){
        return {
            a:1,
            b:2
        }
    }
    let {a,b}=sum()
  • JSON
  • Ajax请求
    axios.get().then(({data})=>{
        console.log(data)
    })

    //等价于
    axios.get().then((res)=>{
        console.log(res.data)
    })

class

class实际上是函数,一个语法糖 

    class People { }
    console.log(typeof People)//function

JS Part

typeof 运算符

  • 能判断值类型
    let a;//undefined
    const str = 'abc'//string
    const n = 100 //number
    const b = true //boolean
    const s = Symbol('s') //symbol
  • 引用类型。能判断函数,能识别引用类型(但不能再继续识别) 
    typeof null //object
    typeof {} //object
    typeof [] //object
    typeof function(){} //function
    typeof Array //function

深拷贝

    function deepClone(obj = {}) {
      if (typeof obj !== 'object' || obj == null) {
        return obj;
      }

      let result;
      obj instanceof Array ? result = [] : result = {}

      for (const key in obj) {
        // 保证key不是原型上的属性
        // hasOwnProperty不会遍历原型上的属性
        if (obj.hasOwnProperty(key)) {
          result[key] = deepClone(obj[key]);
        }
      }

      return result;
    }

==运算符

    obj.a == null
    //相当于
    obj.a === null || obj.a === undefined

除了 == null 之外,其余用 === 进行比较判断

    // 以下是falsely变量,除此之外都是truely变量
    !!0 === false
    !!NaN === false
    !!'' === false
    !!null === false
    !!undefined === false
    !!false === false

未分类 Part

前端基础体系

https://www.jianshu.com/p/3890418ab7cf

https://mm.edrawsoft.cn/template/81442

Daily summary