上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页
摘要: 问题: "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type 'any' because it does not have a type annotation 解决方案: 将this放在函数参数列表上声明类型即可,使用的时候this不会干扰 阅读全文
posted @ 2022-06-20 23:21 IslandZzzz 阅读(12374) 评论(0) 推荐(1) 编辑
摘要: setTimeout 模拟实现 setInterval js单线程,在线程占用时间较长的情况下,setInterval可能会向任务队列里添加很多宏任务 这些宏任务在线程空下来的时候,会依次执行,而不会间隔执行,导致失效 所以使用setTimeout+递归来模拟,只有前一次任务执行了之后,才添加下一次 阅读全文
posted @ 2022-06-20 01:06 IslandZzzz 阅读(333) 评论(0) 推荐(0) 编辑
摘要: for (var index = 1; index < 5; index++) { ((i) => { setTimeout(() => { // console.log(i); }, 1000 * i); })(index) } for (let index = 1; index < 5; ind 阅读全文
posted @ 2022-06-19 17:01 IslandZzzz 阅读(351) 评论(0) 推荐(0) 编辑
摘要: // 红黄绿: 使用异步编程方案, promise, async await等都行 // 循环打印: 一轮打印完了以后递归重复这一过程 const taskRunner = (light, timeout) => { return new Promise((resolve) => { setTime 阅读全文
posted @ 2022-06-19 16:53 IslandZzzz 阅读(356) 评论(0) 推荐(0) 编辑
摘要: 先找到根(父)节点,然后根据根节点的id和数组元素的pid找到对应父子关系 重复上一步骤 const getTree = (root, list) => { if(!Array.isArray(list)) throw 'list must be Array' root = root || list 阅读全文
posted @ 2022-06-19 16:41 IslandZzzz 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Hook定义 useDragList import { useState } from "react"; interface DragPropsType { list: Array<any>, dragItemClassName: string } const checkValidDragItem 阅读全文
posted @ 2022-06-17 18:42 IslandZzzz 阅读(246) 评论(0) 推荐(0) 编辑
摘要: js draggable 拖拽效果 drag 拖拽中 dragstart 开始拖拽 dragover 拖拽悬浮时触发 dragenter 拖入目标节点 dragleave 离开源节点 drop 落进目标节点 event.dataTransfer.setData 拖拽时传输数据,可用于dragstar 阅读全文
posted @ 2022-06-17 15:57 IslandZzzz 阅读(813) 评论(0) 推荐(0) 编辑
摘要: const shuffle = arr => { let len = arr.length let rand = 0 while (len) { rand = Math.floor(Math.random() * len--) ;[arr[len], arr[rand]] = [arr[rand], 阅读全文
posted @ 2022-06-17 14:24 IslandZzzz 阅读(52) 评论(0) 推荐(0) 编辑
摘要: js实现日期转换函数 用yyyy,MM,dd固定字符串做替换 const dateFormat = (date, formatter) => { const fDate = new Date(date) const day = fDate.getDate() const month = fDate. 阅读全文
posted @ 2022-06-17 11:27 IslandZzzz 阅读(34) 评论(0) 推荐(0) 编辑
摘要: bind返回一个函数 闭包保存this, 执行的时候用apply或call绑定this js中new的优先级高于bind Function.prototype._bind = function (context) { if (typeof this !== "function") throw "ty 阅读全文
posted @ 2022-06-14 18:24 IslandZzzz 阅读(26) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页