必背面试题web前端面试题(必背面试题)_Z_Xshan的博客-CSDN博客_web前端面试题
面试官:手写防抖与节流
//防抖
function debounce(func,wait=5000){let timer=0;return function(...args){if (timer) clearTimeout(timer)timer=setTimeout(()=>{console.log(2);func.apply(this,args)},wait)}}//节流
function throttle(func,delay=2000){var timer=1;return function(...args){if(timer){timer=setTimeout(()=>{func.apply(this,args)timer=0},delay)}}
}
面试题:实现instanceof
function _instanceof(example,classFunc){if (typeof example!=='object' || example==null) return falselet proto=Object.getPrototypeOf(example);while(true){if (proto==classFunc.prototype) return true;proto=Object.getPrototypeOf(proto)}}
console.log(_instanceof([], Array)); //true