溺深海 2022-05-04 07:28:45
js 中数组元素的存储方式并不是连续的,而是哈希映射关系。哈希映射关系,可以通过键名 key,直接计算出值存储的位置,所以查找起来很快。推荐一下这篇文章:深究 JavaScript 数组
溺深海 2022-05-03 15:09:42
enum Methods { 'GET', 'POST' } declare function handleRequest(url: string, method: keyof typeof Methods): void; type ReqShape = { url: string; method: keyof typeof Methods; } const req: ReqShape = { url: "https://example.com", method: "GET" }; handleRequest(req.url, req.method);
抛开本节主题来讲,字面量推断的例子中,第二个例子,其实也可以这么干,让类型更通用。
- 共 1 页
- 1
应该这么翻译:
WeakMap
对键名的引用属于弱引用
。不必强调”保持“
ES6 系列之 WeakMap