上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页
摘要: Map Map是JavaScript的一种数据结构,主要用于有序保存键值对,任何值都可以作为一个键或者值。 Map实现了iterator接口,遵循可迭代协议 1 特点 有序插入/输出 任意值都可以作为键 2 key 键的比较基于sameValueZero算法 在作为键的时候,NaN与NaN是相等的 阅读全文
posted @ 2022-06-21 16:07 IslandZzzz 阅读(435) 评论(1) 推荐(0)
摘要: interface和type都可以用作ts中限制变量的类型,它们有一些共同点 都能作为限制变量类型的方式 都能被class实现 但也有所区别 interface可以实现声明合并,type不行 interface A { a: string } interface A{ b:string } cons 阅读全文
posted @ 2022-06-21 11:12 IslandZzzz 阅读(250) 评论(0) 推荐(0)
摘要: type A = { a: number, b: number } type B = { a: number } // 交叉类型, 需要满足A和B的并集 const D: A & B = { a: 1, b: 2 } // 联合类型,需要满足A和B的交集 const E: A | B = { a: 阅读全文
posted @ 2022-06-21 11:07 IslandZzzz 阅读(63) 评论(0) 推荐(0)
摘要: 定义useLazyLoad 思路: 判断图片在视口内就加载,即: 元素距离页面顶部的距离offsetTop < 滚动条高度scrollTop + 视口高clientHeight import { useCallback, useEffect, useState } from 'react' impo 阅读全文
posted @ 2022-06-21 00:20 IslandZzzz 阅读(992) 评论(0) 推荐(0)
摘要: 定义 import { useCallback, useEffect, useRef } from "react" export interface ThrottleRefType { fn: Function, timer?: NodeJS.Timeout } export type Thrott 阅读全文
posted @ 2022-06-21 00:14 IslandZzzz 阅读(969) 评论(0) 推荐(0)
摘要: 定义 import { useCallback, useEffect, useRef } from "react" export interface DebounceRefType { fn: Function, timer?: NodeJS.Timeout } export type Deboun 阅读全文
posted @ 2022-06-21 00:12 IslandZzzz 阅读(1005) 评论(0) 推荐(0)
摘要: 问题 不能将类型“Timeout”分配给类型“number” Type 'Timeout' is not assignable to type 'number'. 解决方案 设置类型为NodeJS.Timeout 清除时使用delete ref.timer + clearTimeout export 阅读全文
posted @ 2022-06-21 00:05 IslandZzzz 阅读(4021) 评论(0) 推荐(0)
摘要: 问题: "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type 'any' because it does not have a type annotation 解决方案: 将this放在函数参数列表上声明类型即可,使用的时候this不会干扰 阅读全文
posted @ 2022-06-20 23:21 IslandZzzz 阅读(13449) 评论(0) 推荐(1)
摘要: setTimeout 模拟实现 setInterval js单线程,在线程占用时间较长的情况下,setInterval可能会向任务队列里添加很多宏任务 这些宏任务在线程空下来的时候,会依次执行,而不会间隔执行,导致失效 所以使用setTimeout+递归来模拟,只有前一次任务执行了之后,才添加下一次 阅读全文
posted @ 2022-06-20 01:06 IslandZzzz 阅读(363) 评论(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 阅读(380) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 49 下一页