js知识点汇总(开发随记-持续更新中...)

55 阅读1分钟

一、类型判断

  • 基本类型(typeof)
numberstringbooleanundefined
typeof(3) === 'number'
  • 引用类型(instanceof)
functionArrayObjectDate
例:([]) instanceof Array
  • 推荐的判断方式
Object.prototype.toString.call([值])
例:Object.prototype.toString.call(0) '[object Number]'

二、继承、原型链

  • 原型链

简单理解:通过__proto__连接起来,组合成一条链路,直到Object.prototype.__proto__指向null为止

image.png

关键词:实例、对象、构造函数、原型(prototype)、隐式原型(proto

构造函数:
function test(name){
   this.name = name;
}

实例:(new 一下)
const newTest = new test('liming')

原型:prototype
每个构造函数都有一个prototype

constructor:
newTest.contructor === test

  • 继承

三、call、apply、bind(手写实现)

都是用来改变this指向

  • call、bind:支持多个入参(_this,arg1,arg2...),其中bind要手动触发执行
  • apply:第二个入参是数组(_this,[arg1,arg2...])

四、set、map、Promise

  • set

去重:new Set([...]);去重后转成数组Array.from(new Set([...]))

  • map

枚举、映射处理、缓存 for of遍历返回键值对[key,value],forEach遍历返回(value,key)更方便处理

  • Promise(手写实现)

五、proxy、reflect(操作对象)、事件循环

  • proxy(代理)

set、get拦截对象

  • reflect

Reflect.has、Reflect.get、Reflect.set

  • 事件循环

要清楚微任务和宏任务执行顺序

六、Object类常见方法

Object.defineProxy

七、常见算法

  • 几种排序