手写new
//使用new时:1内部生成一个obj 2.obj的__proto__指向原型对象 3.obj绑定this
//返回一个新对象(如果func没有返回对象则返回obj,如果func返回了对象就返回此对象)
function myNew(func,...args){
let obj={
}
obj.__proto__=func.prototype
let result=func.apply(obj,args)
return result instanceof Object?result:obj;
}
手写防抖
核心思想: 每次事件触发则删除原来的定时器,建立新的定时器。跟王者荣耀的回城功能类似,你反复触发回城功能,那么只认最后一次,从最后一次触发开始计时。
function debounce(fn,wait){
let timeout=null
return function(...args){
let context&#