摘要:
//generator是可以用来控制迭代器的函数,可以暂停,也可以任何时候恢复function * loop () { for(let i = 0; i < 5; i++) { yield console.log(i) } } const l = loop() l.next() l.next() f 阅读全文
2020年1月21日
2020年1月18日
摘要:
let options = { title: 'menu', width: 100, height: 200 } //如果简写,变量名必须和属性名一致 let {title,width,height} = options console.log(title,width,height) let {ti 阅读全文
摘要:
//数组解构 let arr = [1,2,3,4,5,6,7] let [one,two] = arr let [one, , ,four] = arr console.log(one,two,four) let arr = 'abcd' let [first, ,third] = arr con 阅读全文
摘要:
//包含变量或表达式 const a = 10 const b = 20 const c = 'html' const str = `my age is ${a + b} i love ${c}` //包含逻辑运算的用法 function Price (strings,type){ let s1 = 阅读全文
摘要:
const s = 'aaa_aa_a' const r1 = /a+/g const r2 = /a+/y console.log(r1.exec(s)) //aaa console.log(r2.exec(s)) //aaa console.log(r1.exec(s)) //aa consol 阅读全文
摘要:
const target = { a: { b: { c: { d: 1 } }, e: 5, f: 6, h: 10 } } const source = { a: { b: { c: { d: 1 } }, e: 2, f: 3 } } Object.assign(target, source) 阅读全文
2020年1月17日
摘要:
//map实例化,存入的数据格式是二维数组 let map = new Map() //添加 map.set(1,2) map.set(3,'value-3') //删除,通过key删除 map.delete(1) //清空 map.clear() //获取长度 map.size //判断是否存在对 阅读全文
摘要:
set:无序的不重复的value的集合体 //实例化容器 let s = new Set()//方法一 let s = new Set([1,2,3,4])//方法二,里面存储可循环的数据,不一定是数组,对象,只要是可循环的都可以 //添加数据 //s.add('hello') //s.add('g 阅读全文
摘要:
function sum (x = 1, y = 2, z = 3) { return x + y + z } let data = [4,5,9] console.log(sum(data[0],data[1],data[2])) console.log(sum.apply(this,data)) 阅读全文