2026前端面试题(六)
防抖const debounce (fn,delay300) { let timer null return function(...args){ clearTimeout(timer) timer setTimeout(()fn.apply(this.args),delay) } }节流const throttle (fn,delay300){ let lock false return function(...args){ if(!lock){ lock true setTimeout((arg){ fn.apply(this.args) lock false },delay) } } }深拷贝const deepClone (obj,map new Weepmap()) { if(obj null || type obj ! object) return obj if(map.has(obj)) return map.get(obj) const target Array.isArray(obj) ? [] : {} map.set(obj,target) Reflect.ownKeys(obj).forEach(key { target[key] deepClone(obj[key],map) }) return target }手写Promise 简易版class MyPromise{ constructor(executor) { this.state pending this.val null this.onFulfiled [] this.onRejected [] const resolve v { if(this.state ! pending) return this.state fulfiled this.val v this.onFulfiled.forEach(fn fn(v)) } const reject e { if(this.state ! pending) return this.state rejected this.val e this.onRejected.forEach(fn fn(e)) } try { executor(resolve, reject)} catch(err) {reject(err)} } then(suc, err) { suc suc || (v v) err err || (e { throw e }) return new MyPromise((res, rej) { const cb fn v setTimeout(() { try { const r fn(v); res(r) } catch (e) { rej(e) } }) if (this.state fulfilled) cb(suc)(this.val) else if (this.state rejected) cb(err)(this.val) else { this.onFulfilled.push(cb(suc)) this.onRejected.push(cb(err)) } }) } }手写bind/call/bind# call Function.prototype.myCall function(ctx, ...args) { ctx ctx || window ctx.fn this const res ctx.fn(...args) delete ctx.fn return res } # apply Function.propotype.myApply function(ctx, args []) { ctx ctx || window ctx.fn this const res ctx.fn(...args) delete ctx.fn return res } # bind(返回新函数) Function prototype.myBind function(ctx, ...args1) { const fn this return function(...args2) { return fn.myCall(ctx, ...args1, ...args2) } }数组去重、flat扁平化# 数组去重new Set function unique(arr){ return [...new Set(arr)] } # flat 扁平化无限层级 function flat(arr){ return arr.reduce((pre,cur) pre.concat(Array.isArray(cur) ? flat(cur) :cur),[]) }new实现const myNew (fn, ...args) { const obj object.create(Fn.prototype) const res Fn.apply(obj, args) return typeof res object res ! null ? res : obj }instanceOfconst myInstanceof (left, right) { let proto Object.getPrototypeOf(left) while(proto) { if(proto right.prototype) return true proto Object.getPrototypeOf(proto) } return false }发布订阅模式class EventBus{ constructor() { this.events {} } on(type, fn){ if(! this.events[type].push(fn)) } emit(type, ...args) { this.events[type]?.forEach(fn fn(...srgs))) } off(type, fn) { if(!this.events[type]) return this.events[type] this.events[type].filter(item item ! fn) } }简易Ajaxfunction ajax({ url, method GET, data }) { return new Promise((res, rej) { const xhr new XMLHttpRequest() let params if (data) params new URLSearchParams(data).toString() let reqUrl url if (method.toUpperCase() GET params) reqUrl ? params xhr.open(method, reqUrl) if (method.toUpperCase() ! GET) { xhr.setRequestHeader(Content-Type, application/x-www-form-urlencoded) } xhr.onload () xhr.status 200 xhr.status 300 ? res(xhr.response) : rej(xhr.statusText) xhr.onerror () rej(请求失败) xhr.send(method.toUpperCase() GET ? null : params) }) }

相关新闻

餐饮供应链行业企业获客软件精准拓客方法论:基于客户类型的多维筛选策略

餐饮供应链行业企业获客软件精准拓客方法论:基于客户类型的多维筛选策略

餐饮供应链行业的客户类型涵盖终端餐饮门店、食品加工企业和批发商,各类客户的行业分布和筛选策略存在显著差异。本文构建基于客户类型的三维筛选框架,分析不同产品品类对应的最优行业分类选择和条件组合,为餐饮供应链销售提供精准拓客方法论…

2026/11/2 21:32:25 阅读更多 →
ABAP 里有没有 RxJS Marble Diagram,真正的差别不在画法,而在时间模型

ABAP 里有没有 RxJS Marble Diagram,真正的差别不在画法,而在时间模型

最近讨论 ABAP 是否存在类似 RxJS 的 Observable、Observer、Hot Observable、Cold Observable 这些概念时,很容易继续追到另一个很有意思的问题,既然 RxJS 能用 Marble diagram 把异步事件画成一条时间轴,那么 ABAP 里有没有类似技术。 这个问题的答案很明确。 截至 2026…

2026/11/8 6:06:21 阅读更多 →
Win11Debloat实测:半小时卸载预装软件、关闭遥测,新电脑终于不卡了

Win11Debloat实测:半小时卸载预装软件、关闭遥测,新电脑终于不卡了

Win11Debloat实测:半小时卸载预装软件、关闭遥测,新电脑终于不卡了 【免费下载链接】Win11Debloat A simple, lightweight PowerShell script that allows you to remove pre-installed apps, disable telemetry, as well as perform various other chan…

2026/11/14 13:40:52 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/19 21:38:27 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/19 21:38:49 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/19 21:39:09 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/19 21:36:50 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/19 21:37:45 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/19 21:36:20 阅读更多 →

日新闻

周新闻

月新闻