上一页 1 2 3 4 5 6 ··· 8 下一页
摘要: 具有Iterator接口的数据都可以解构赋值 数组的解构赋值 let arr = [1, 2, 3, 4] let [a, , c] = arr console.log(a, c) 1 3 let [a = 1, ...b] = [undefined, 2, 3, 4, 5, 6] console. 阅读全文
posted @ 2020-05-18 18:36 AllenZhang_(*^▽^*) 阅读(118) 评论(0) 推荐(0) 编辑
摘要: y修饰符:也叫粘连(sticky)修饰符,作用与g修饰符类似,也是全局匹配 g修饰符只要剩余位置中存在匹配就可,而y修饰符确保匹配必须从剩余的第一个位置开始 对比: // g let a = '111 11 1' let r1 = /\d+/g console.log(r1.exec(a)) con 阅读全文
posted @ 2020-05-03 18:30 AllenZhang_(*^▽^*) 阅读(461) 评论(0) 推荐(0) 编辑
摘要: map类似于对象,也是键值对的集合,但是“键”的范围不限于字符串,各种类型的值(包括对象)都可以当作键。 任何具有 Iterator 接口、且每个成员都是一个双元素的数组的数据结构都可以当作Map构造函数的参数 据说性能要比对象好一些 map的创建和修改 let map1 = new Map([[1 阅读全文
posted @ 2020-05-01 17:55 AllenZhang_(*^▽^*) 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 感觉跟Python里的set集合差不多啊(都可以去重),但是es6里的set实际上是对象,里面有键值对 创建 let a = new Set([1, 2, 3]) // 或者 let a = new Set() 添加数据 let a = new Set([1, 2, 3]) a.add(4) con 阅读全文
posted @ 2020-04-28 23:48 AllenZhang_(*^▽^*) 阅读(158) 评论(0) 推荐(0) 编辑
摘要: ES5利用arguments // ES5 function sum () { let num = 0 Array.prototype.forEach.call(arguments, function (v) { num += v * 1 }) return num } console.log(su 阅读全文
posted @ 2020-04-28 22:22 AllenZhang_(*^▽^*) 阅读(116) 评论(0) 推荐(0) 编辑
摘要: // ES5 function a (x, y) { x = x undefined ? 1 : 1 y = y undefined ? 2 : y return x + y } console.log(a())3 // ES6 function a (x = 1, y = 2) { return 阅读全文
posted @ 2020-04-21 23:24 AllenZhang_(*^▽^*) 阅读(133) 评论(0) 推荐(0) 编辑
摘要: ES5声明一个类 let Animal = function (type) { this.type = type } Animal.prototype.eat = function () { console.log('eat') } ES6声明一个类 class Animal { // 构造函数 c 阅读全文
posted @ 2020-04-20 22:32 AllenZhang_(*^▽^*) 阅读(95) 评论(0) 推荐(0) 编辑
摘要: ES6之前 let arr = Array(5) let arr = [] Array() // [] Array(3) // [, , ,] Array(3, 11, 8) // [3, 11, 8] ES6 let arr = Array.of(1, 2, 3, 4, 5) // [1, 2, 阅读全文
posted @ 2020-04-05 14:01 AllenZhang_(*^▽^*) 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 伪数组: 1、以索引方式存储数据 2、必须带有length属性 ES5(Array.prototype.slice) let args = [].slice.call(arguments) // collection let imgs = [].slice.call(document.querySe 阅读全文
posted @ 2020-04-02 18:23 AllenZhang_(*^▽^*) 阅读(442) 评论(0) 推荐(0) 编辑
摘要: let arr = [1, 2, 3, 4, 5, 6] ES3 for (let i = 0;i < arr.length;i++) { // ...... } ES5 arr.forEach((v) => { // 缺点是不能用continue和break }) arr.every((v) => 阅读全文
posted @ 2020-03-30 23:06 AllenZhang_(*^▽^*) 阅读(257) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 8 下一页