摘要:
前言 JavaScript 中最大的一个安全问题,也是最令人困惑的一个问题,就是在某些情况下this的值是如何确定的。有js基础的同学面对这个问题基本可以想到:this的指向和函数调用的方式相关。这当然是正确的,然而,这几种方式有什么联系吗?这是我接下来要说明的问题。 this从哪里来 this 是 阅读全文
摘要:
原生Math.max方法 Math.max 方法不能接收数组,可以使用ES6的...将数组打散 const arr = [111, 12, 111, 34, 2, 5, 76]; console.log(Math.max(...arr)); 当然也可以用apply方法调用 console.log(M 阅读全文
摘要:
双重for循环依次比较 将结果函数中的元素与原数组中的元素依次比较,重复的元素舍弃,不重复的元素添加仅结果函数。 function removeRepeatArr(arr) { const result = []; for (let i = 0, len = arr.length; i < len; 阅读全文
摘要:
函数内部直接或间接调用函数本身为递归 阅读全文
摘要:
forEach const root = this; Array.prototype.myForEach = function(fn, context) { // 可选参数, 设置回调中的this指向 context = context || root; if (typeof fn !== 'fun 阅读全文
摘要:
call、apply和bind的实现 阅读全文
摘要:
通过 queueMicrotask() 使用微任务 阅读全文
摘要:
// JS主任务(宏任务1)开始,输出1.Start console.log('1.Start') // setTimeout为宏任务(2),加入宏任务事件循环 setTimeout(function() { console.log('2.Timer is on'); }); new Promise 阅读全文
摘要:
项目综述 在页面中模拟某操作系统的操作界面,提供应用窗口的最大化、最小化、还原等功能 需求 对一个应用窗口标题栏双击使其铺满整个视口,再次双击还原到原来大小,和位置 部分代码片段如下: win.addEventListener('dblclick', (event) => { if (cache & 阅读全文
摘要:
1. 选择器的权值 权值:选择器的针对性越强,权值越高。 权值排序:!important > 行内样式 > id > 类 | 伪类 | 属性 > 标签 > 通配符。 选择器 权值 继承,通配符等 0.1 标签选择器 1 类、伪类、属性选择器 10 id选择器 100 行内样式 1000 !impor 阅读全文