实现防抖函数(debounce) 防抖函数原理:在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时. 那么与节流函数的区别直接看这个动画实现即可. 手写简化版: // 防抖函数 const debounce = (fn, delay) => { let timer = null; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { fn.apply(this, args); }, del…
几道JS代码手写面试题   (1) 高阶段函数实现AOP(面向切面编程)    Function.prototype.before = function (beforefn) {        let _self = this; // 缓存原函数的引用        return function () { // 代理函数            beforefn.apply(this, arguments); // 执行前置函数            return _self.apply(thi…
56 道高频 JavaScript 与 ES6+ 的面试题及答案 :https://segmentfault.com/a/1190000020082089?utm_source=weekly&utm_medium=email&utm_campaign=email_weekly&tdsourcetag=s_pcqq_aiomsg…
1.看一下正常使用的new方法 function father(name){ this.name=name; this.sayname=function(){ console.log(this.name) } } var son=new father('kimi') dog.sayname(); 输出结果: kimi 2.手写一个new方法 function father(name){ this.name=name; this.sayname=function(){ console.log(th…
前言 现在不管是大公司还是小公司,去面试都会问到多线程与并发编程的知识,大家面试的时候这方面的知识一定要提前做好储备. 关于多线程与并发的知识总结了一个思维导图,分享给大家 1.Java中实现多线程有几种方法 (1)继承Thread类: (2)实现Runnable接口: (3)实现Callable接口通过FutureTask包装器来创建Thread线程: (4)使用ExecutorService.Callable.Future实现有返回结果的多线程(也就是使用了ExecutorService来管…
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js图片轮播切换</title> <style type="text/css"> .imgCon{width: 400px;height: 400px;border: 2px solid #DCDCDC;margin: 100px auto;position: re…
LRU 是 Least Recently Used 的缩写,即最近最少使用.作为一种经典的缓存策略,它的基本思想是长期不被使用的数据,在未来被用到的几率也不大,所以当新的数据进来时我们可以优先把这些数据替换掉. 一.基本要求 固定大小:限制内存使用. 快速访问:缓存插入和查找操作应该很快,最好是 O(1) 时间. 在达到内存限制的情况下替换条目:缓存应该具有有效的算法来在内存已满时驱逐条目. 二.数据结构 下面提供两种实现方式,并完成相关代码. 2.1 Map 在 Javascript 中,Ma…
demo let timeout = (sec, num) => { const now = new Date().getTime() // 获取进入方法时的时间 let flag = true let count = 0 while (flag) { count++ const after = new Date().getTime() // 执行到此的时间 const dealy = sec * 1000 if (after - dealy >= now) { // 比较是否已经过了设置的时…
let setTimeout = (sec, num) => { // 初始当前时间 const now = new Date().getTime() let flag = true let count = 0 while (flag) { count++ // 再次运行时获取当前时间 const after = new Date().getTime() // 需要等待的时间 const dealy = sec * 1000 // 当前运行时间 - 初始当前时间 >= 等待时间 ===>…
目录 手写数组衍生方法 1.检测是否为数组 2.类数组转化为数组 3.数组扁平化 4.数组去重 5.数组使用Math.max 手写数组内置方法 1. Array.prototype.filter 2. Array.prototype.map 3. Array.prototype.reduce(难点) 4. Array.prototype.forEach 5. Array.prototype.some 6. Array.prototype.find 7. Array.prototype.unshi…