上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页
摘要: 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 邢韬 阅读(99) 评论(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 邢韬 阅读(46) 评论(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 邢韬 阅读(428) 评论(0) 推荐(0)
摘要: Int8Array // 有符号字节,元素值在0-255之间,溢出会翻转 Uint8Array // 无符号字节,元素值在0-255之间,溢出会翻转 Uint8ClampedArray // 无符号字节,溢出不归零,会顾定为0或255(绘制颜色时很有用) Int16Array // 有符号16位短整 阅读全文
posted @ 2021-12-15 19:58 邢韬 阅读(58) 评论(0) 推荐(0)
摘要: 映射 映射可以理解为字典,不同于数组,允许使用任何值作为索引,映射的键是唯一的,若传入重复的键值对,会用新的值代替旧的值 创建映射 let m = new Map() let n = new Map([ // Map(2) { 'one' => 1, 'two' => 2 } ["one", 1], 阅读全文
posted @ 2021-12-15 15:18 邢韬 阅读(44) 评论(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 邢韬 阅读(46) 评论(0) 推荐(0)
摘要: 文件目录如下 静态加载 静态加载模块,保证导入的值在代码运行之前就可以使用 import {add} from "./module.js" add(1, 2) // 3 动态加载 ES2020引入import()支持动态加载模块,如通过网络传输的模块,由于动态加载模块是异步的,所以要配合then或 阅读全文
posted @ 2021-12-14 21:27 邢韬 阅读(47) 评论(0) 推荐(0)
摘要: call和apply允许间接调用一个函数 call和apply可以改变this指向,或者可以说是将一个函数作为某个对象的方法进行调用 call将参数逐一传入,apply是以数组形式进行传入 const o = { x: 1 } const f = function(y, z){ return thi 阅读全文
posted @ 2021-12-13 21:06 邢韬 阅读(37) 评论(0) 推荐(0)
摘要: 设置默认参数,默认参数可以使用前面的形参来定义 const rectangle = (width, height = width * 2) => {} 剩余形参,是个数组,必须放在最后,若不传就是空 function max(first, ...args){ let maxVal = first f 阅读全文
posted @ 2021-12-13 21:04 邢韬 阅读(76) 评论(0) 推荐(0)
摘要: 构造函数调用会创建一个新对象,一般不使用return,会默认返回当前对象 使用return会有2种情况 1.返回一个新的对象,则会变成该新对象 2.返回一个原始值,则还是返回当前对象,不会返回该原始值 const Obj1 = function(){ this.name = "abc" } cons 阅读全文
posted @ 2021-12-13 21:01 邢韬 阅读(103) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页