当前位置: 首页 > wzjs >正文

怎么编辑自己的网站wordpress分类权限

怎么编辑自己的网站,wordpress分类权限,wordpress 附件上传插件下载,建筑网校排名前十的品牌前端面试中,JS 手撕题是高频考点,主要考察 编程能力、算法思维、JS 核心知识。以下是最常见的手撕题分类 代码示例: 目录 📌 1. 手写函数柯里化📌 2. 手写 debounce(防抖)📌 3. 手写…

前端面试中,JS 手撕题是高频考点,主要考察 编程能力、算法思维、JS 核心知识。以下是最常见的手撕题分类 + 代码示例


目录

    • 📌 1. 手写函数柯里化
    • 📌 2. 手写 `debounce`(防抖)
    • 📌 3. 手写 `throttle`(节流)
    • 📌 4. 手写深拷贝
    • 📌 5. 手写 `new` 操作符
    • 📌 6. 手写 `call` / `apply` / `bind`
    • 📌 7. 手写 `Promise.all`
    • 📌 8. 实现 LRU 缓存
    • 📌 9. 手写 `instanceof`
    • 📌 10. 数组去重

📌 1. 手写函数柯里化

题目:实现一个 curry(fn) 函数

function curry(fn, ...args) {return args.length >= fn.length? fn(...args): (...nextArgs) => curry(fn, ...args, ...nextArgs);
}// 示例函数
function sum(a, b, c) {return a + b + c;
}const curriedSum = curry(sum);
console.log(curriedSum(1)(2)(3)); // 6
console.log(curriedSum(1, 2)(3)); // 6

📌 2. 手写 debounce(防抖)

题目:实现 debounce(fn, delay)

function debounce(fn, delay) {let timer;return function (...args) {clearTimeout(timer);timer = setTimeout(() => fn.apply(this, args), delay);};
}// 示例:输入框搜索
const search = debounce(() => console.log("搜索 API 请求"), 500);
document.getElementById("searchInput").addEventListener("input", search);

📌 3. 手写 throttle(节流)

题目:实现 throttle(fn, delay)

function throttle(fn, delay) {let lastTime = 0;return function (...args) {const now = Date.now();if (now - lastTime >= delay) {fn.apply(this, args);lastTime = now;}};
}// 示例:鼠标滚动触发
const handleScroll = throttle(() => console.log("滚动中..."), 1000);
window.addEventListener("scroll", handleScroll);

📌 4. 手写深拷贝

题目:实现 deepClone(obj)

function deepClone(obj, map = new WeakMap()) {if (typeof obj !== "object" || obj === null) return obj;if (map.has(obj)) return map.get(obj); // 处理循环引用let clone = Array.isArray(obj) ? [] : {};map.set(obj, clone);for (let key in obj) {if (obj.hasOwnProperty(key)) {clone[key] = deepClone(obj[key], map);}}return clone;
}// 示例
const obj = { a: 1, b: { c: 2 } };
const copy = deepClone(obj);
console.log(copy);

📌 5. 手写 new 操作符

题目:实现 myNew(fn, ...args)

function myNew(fn, ...args) {const obj = Object.create(fn.prototype); // 创建空对象并继承构造函数原型const result = fn.apply(obj, args); // 执行构造函数return result instanceof Object ? result : obj; // 处理返回值
}// 示例
function Person(name) {this.name = name;
}
const p = myNew(Person, "Alice");
console.log(p.name); // Alice

📌 6. 手写 call / apply / bind

✅ 手写 call

Function.prototype.myCall = function (context, ...args) {context = context || window;const fnKey = Symbol();context[fnKey] = this;const result = context[fnKey](...args);delete context[fnKey];return result;
};// 示例
function greet() {console.log(`Hello, ${this.name}`);
}
const obj = { name: "Alice" };
greet.myCall(obj); // Hello, Alice

✅ 手写 apply

Function.prototype.myApply = function (context, args = []) {context = context || window;const fnKey = Symbol();context[fnKey] = this;const result = context[fnKey](...args);delete context[fnKey];return result;
};

✅ 手写 bind

Function.prototype.myBind = function (context, ...args) {const self = this;return function (...innerArgs) {return self.apply(context, [...args, ...innerArgs]);};
};// 示例
const boundFn = greet.myBind(obj);
boundFn(); // Hello, Alice

📌 7. 手写 Promise.all

题目:实现 myPromiseAll(promises)

function myPromiseAll(promises) {return new Promise((resolve, reject) => {let results = [];let count = 0;if (promises.length === 0) resolve([]);promises.forEach((p, index) => {Promise.resolve(p).then(value => {results[index] = value;count++;if (count === promises.length) resolve(results);},error => reject(error));});});
}// 示例
const p1 = Promise.resolve(1);
const p2 = Promise.resolve(2);
const p3 = new Promise(resolve => setTimeout(() => resolve(3), 1000));myPromiseAll([p1, p2, p3]).then(console.log); // [1, 2, 3]

📌 8. 实现 LRU 缓存

题目:设计一个 LRUCache

class LRUCache {constructor(capacity) {this.capacity = capacity;this.cache = new Map();}get(key) {if (!this.cache.has(key)) return -1;let value = this.cache.get(key);this.cache.delete(key);this.cache.set(key, value);return value;}put(key, value) {if (this.cache.has(key)) this.cache.delete(key);this.cache.set(key, value);if (this.cache.size > this.capacity) {this.cache.delete(this.cache.keys().next().value); // 删除最早的键}}
}// 示例
const cache = new LRUCache(2);
cache.put(1, "A");
cache.put(2, "B");
console.log(cache.get(1)); // A
cache.put(3, "C"); // 淘汰 key=2
console.log(cache.get(2)); // -1

📌 9. 手写 instanceof

题目:实现 myInstanceOf(obj, constructor)

function myInstanceOf(obj, constructor) {let proto = Object.getPrototypeOf(obj);while (proto) {if (proto === constructor.prototype) return true;proto = Object.getPrototypeOf(proto);}return false;
}// 示例
console.log(myInstanceOf([], Array)); // true
console.log(myInstanceOf({}, Array)); // false

📌 10. 数组去重

const uniqueArray = arr => [...new Set(arr)];
console.log(uniqueArray([1, 2, 2, 3])); // [1, 2, 3]

http://www.dtcms.com/wzjs/807312.html

相关文章:

  • 天津实用网站建设平台柳州房地产网站建设
  • 机械设备如何做网站做英文网站賺钱
  • 网站制作什么品牌好西安建站公司模板
  • 网站备案服务内容灌南县规划局网站理想家园规划建设
  • 兰州西固区公司网站建设百度站长管理平台
  • 建设网站的方案贴吧 wordpress
  • 免费网站制作新闻wordpress手机分享插件
  • 百度改网站描述东莞专业网站建设公司
  • iis打开网站变成下载唐山网站排名提升
  • 黑龙江网站设计蓬莱做网站那家好
  • 做网站需要的导航手机与pc的网站开发
  • wordpress博客站模板外贸网络推广是什么
  • php wap网站源码wordpress首页怎么美化
  • 小米手机如何做游戏视频网站夺宝网站还可以做吗
  • 商城网站开发报价wordpress官网案例
  • 北京网站建设亿玛酷出名5项目外包平台接活
  • 网站优化建设兰州做搜狗pc网站优化
  • 中国建设银行数据管理部网站wordpress设置静态之后文章打不开
  • 如何选择郑州网站建设做物流网站有哪些内容
  • 运城市网站建设网站建设工作小组分工
  • 郴州网站设计公司设备建设网站
  • qq网站登录网址北京网站高端定制
  • 不写编程可以做网站建设网校网站模板
  • 网站优化意见免流服务器
  • 好医生网站怎么做不了题目了wordpress多域名配置
  • 成品网站货源1688免费网站建设设计的流程
  • 装饰公司网站建设效果做网站的费用计入什么科目
  • 网站文字变白色代码怎么做软件设计师好考吗
  • 阿里巴巴的网站应该怎么做网站文章页图片不显示图片
  • 蛋糕网站建设末班网页图片设置