摘要: URL 创建URL 使用URL对象时,要传入一个绝对URL作为参数 let url = new URL("https://127.0.0.1:8080/path/name?age=18&sex=man#hashtest") url.href // https://127.0.0.1:8080/pat 阅读全文
posted @ 2021-12-15 22:50 邢韬 阅读(133) 评论(0) 推荐(0) 编辑
摘要: let o = { a: 1, b: 2, c: 3 } let s = JSON.stringify(o) typeof s // string let p = JSON.parse(s) typeof p // object 如果传入了json不支持的数据结构,例如Map, Set, RegEx 阅读全文
posted @ 2021-12-15 22:46 邢韬 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 通过继承原生Error类,实现定制的error class HTTPError extends Error{ constructor(status, statusText, url){ super(`${status} ${statusText}: ${url}`) this.status =sta 阅读全文
posted @ 2021-12-15 22:44 邢韬 阅读(34) 评论(0) 推荐(0) 编辑
摘要: Date() 创建日期对象 若不传参数,则输出该对象会返回当前时间 let now = new Date() 若传一个数值参数参数,则将其视为毫秒数,计算1970年1月1日经过了相应毫秒数后的日期 let epoch = new Date(0) // 1970-01-01T00:00:00.000Z 阅读全文
posted @ 2021-12-15 22:43 邢韬 阅读(376) 评论(0) 推荐(0) 编辑
摘要: Int8Array // 有符号字节,元素值在0-255之间,溢出会翻转 Uint8Array // 无符号字节,元素值在0-255之间,溢出会翻转 Uint8ClampedArray // 无符号字节,溢出不归零,会顾定为0或255(绘制颜色时很有用) Int16Array // 有符号16位短整 阅读全文
posted @ 2021-12-15 19:58 邢韬 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 映射 映射可以理解为字典,不同于数组,允许使用任何值作为索引,映射的键是唯一的,若传入重复的键值对,会用新的值代替旧的值 创建映射 let m = new Map() let n = new Map([ // Map(2) { 'one' => 1, 'two' => 2 } ["one", 1], 阅读全文
posted @ 2021-12-15 15:18 邢韬 阅读(31) 评论(0) 推荐(0) 编辑
摘要: Set集合 集合的使用 创建集合,参数类型没有明确限制,但必须是一个可迭代对象,集合是不能包含重复值的 let s = new Set() let t = new Set([1, s]) let uniqe = new Set("Mississippi") // "M", "i", "s", "p" 阅读全文
posted @ 2021-12-15 13:28 邢韬 阅读(32) 评论(0) 推荐(0) 编辑