news 2026/8/14 15:28:51

2026前端面试题(六)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
2026前端面试题(六)

防抖

const debounce = (fn,delay=300) =>{ let timer = null return function(...args){ clearTimeout(timer) timer = setTimeout(()=>fn.apply(this.args),delay) } }

节流

const throttle = (fn,delay=300)=>{ 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 }

instanceOf

const 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) } }

简易Ajax

function 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) }) }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/14 15:24:13

飞算JavaAI 智能会话深度解析:三种模式让AI成为你的全能编程搭档

飞算JavaAI 智能会话深度解析&#xff1a;三种模式让AI成为你的全能编程搭档 编程过程中遇到Bug怎么办&#xff1f;代码需要重构怎么搞&#xff1f;新功能不会写怎么破&#xff1f;飞算JavaAI智能会话提供三种模式&#xff0c;覆盖从问答到自动化编程的全场景需求。 一、智能会…

作者头像 李华
网站建设 2026/8/14 15:19:22

Kimi LeetCode 3901. 好子序列查询 Rust实现

根据搜索结果&#xff0c;LeetCode 3901「好子序列查询」的核心思路是&#xff1a;线段树 GCD。下面给出 Rust 实现。---思路1. 只关心 p 的倍数&#xff1a;如果 nums[i] 不是 p 的倍数&#xff0c;它对 GCD 为 p 的子序列没有贡献&#xff0c;在线段树中视为 0。 2. 线段树维…

作者头像 李华
网站建设 2026/8/14 15:17:50

2026年六西格玛黑带培训费用曝光!六大机构价格排名及优缺点深度测评

H1: 2026年六西格玛黑带培训费用全解析&#xff1a;品牌性价比横向测评与推荐 TL;DR&#xff1a;六西格玛黑带培训费用因机构、课程深度、授课形式差异较大&#xff0c;通常在1.5万至4万元区间。本文从行业视角横向测评主流培训机构的定价体系、课程配置与适用场景&#xff0c…

作者头像 李华
网站建设 2026/8/14 15:14:14

AI工具出海竞争已经进入新阶段

工具的商业化突围&#xff0c;不在工具本身&#xff0c;而在工具背后那套被市场验证过的生产范式。 提及科幻作品&#xff0c;无论是在大银幕、还是长剧、短剧领域&#xff0c;都是非常难啃的骨头。与常见的依赖台词和人物关系的题材不同&#xff0c;科幻对视觉一致性的要求近…

作者头像 李华
网站建设 2026/8/14 15:13:27

低轨卫星终端相控阵天线波束展宽工程实现:孔径截断法(关闭部分阵元)的增益损失与展宽倍数计算_CSDN发布20260809174028

低轨卫星终端相控阵天线波束展宽工程实现&#xff1a;孔径截断法&#xff08;关闭部分阵元&#xff09;的增益损失与展宽倍数计算 低轨卫星终端在信标捕获阶段&#xff0c;相控阵天线波束宽度往往只有3左右&#xff0c;而卫星相对终端的运动轨迹却可能横跨数十度空域——工程师…

作者头像 李华