随笔分类 -  ES6

深拷贝
摘要:let cnData=JSON.parse(JSON.stringify(data)); 阅读全文
posted @ 2019-03-12 10:29 chenlw101 阅读(99) 评论(0) 推荐(0)
es6(16)--Decorator
摘要:1 //Decorator:修饰器,是一个函数用来修改类的行为 2 { 3 //只读 4 let readonly=function(target,name,descriptor){ 5 descriptor.writable=false; 6 return descriptor; 7 }; 8 class Test... 阅读全文
posted @ 2018-06-26 10:34 chenlw101 阅读(116) 评论(0) 推荐(0)
es6(14)--iterator for ...of循环
摘要:1 //iterator for ...of循环 2 { 3 let arr=['hello','world']; 4 let map=arr[Symbol.iterator](); 5 console.log(map.next()) 6 console.log(map.next()) 7 console.log(map.next()) ... 阅读全文
posted @ 2018-06-26 10:32 chenlw101 阅读(106) 评论(0) 推荐(0)
es6(15)--generator
摘要:1 //generator处理异步,下一步用next,遇到return或者yied就会停止 2 { 3 //generator基本定义 4 let tell=function* (){ 5 yield 'a'; 6 yield 'b'; 7 return 'c' 8 }; 9 le... 阅读全文
posted @ 2018-06-26 10:32 chenlw101 阅读(101) 评论(0) 推荐(0)
es6(13)--Promise
摘要:1 //Promise 2 3 { 4 //原始方法 5 let ajax=function(callback){ 6 console.log('执行') 7 setTimeout(function(){ 8 callback&&callback.call() 9 },1... 阅读全文
posted @ 2018-06-26 10:31 chenlw101 阅读(131) 评论(0) 推荐(0)
es6(12)--类,对象
摘要:1 //类,对象 2 { 3 //基本定义和生成实例 4 class Parent{ 5 //定义构造函数 6 constructor(name='QQQ'){ 7 this.name=name; 8 } 9 } 10 let v_parent=new Parent('v')... 阅读全文
posted @ 2018-06-26 10:30 chenlw101 阅读(105) 评论(0) 推荐(0)
es6(11)--Proxy,Reflect
摘要:1 //Proxy,Reflect 2 3 { 4 let obj={ 5 time:'2018-06-25', 6 name:'net', 7 _r:123 8 }; 9 let monitor = new Proxy(obj,{ 10 //拦截对象属性的读取 11... 阅读全文
posted @ 2018-06-26 10:29 chenlw101 阅读(118) 评论(0) 推荐(0)
es6(10)--Set,Map(2)
摘要:1 //Map与Array的对比 2 { 3 let map=new Map(); 4 let array=[]; 5 //增 6 map.set('t',1); 7 array.push({t:1}); 8 console.info('map-Array',map,array); 9 //查 10 let map... 阅读全文
posted @ 2018-06-26 10:28 chenlw101 阅读(89) 评论(0) 推荐(0)
es6(10)--Set,Map(1)
摘要:1 //Set 2 { 3 let list=new Set(); 4 list.add(5);//添加 5 list.add(7); 6 //属性size就是长度 7 console.log('size',list.size);//2 8 } 9 { 10 let arr = [1,2,3,4,5]; 11 let li... 阅读全文
posted @ 2018-06-26 10:27 chenlw101 阅读(103) 评论(0) 推荐(0)
es6(9)--Symbol
摘要:1 //Symbol生成一个独一无二的值,生成的值不会相等 2 { 3 //声明1 4 let a1=Symbol(); 5 let a2=Symbol(); 6 console.log(a1===a2);//false 7 //声明2 8 let a3=Symbol.for('a3'); 9 let a4=Symbol.... 阅读全文
posted @ 2018-06-26 10:26 chenlw101 阅读(109) 评论(0) 推荐(0)
es6(8)--对象
摘要:1 //对象 2 { 3 //简洁表示法 4 let o = 1; 5 let k = 2; 6 let es5 = { 7 o:o, 8 k:k 9 }; 10 let es6 = { 11 o, 12 k 13 }; 14 console.log(... 阅读全文
posted @ 2018-06-26 10:25 chenlw101 阅读(90) 评论(0) 推荐(0)
es6基础(7)--函数扩展
摘要:1 { 2 //有默认值的后面如果有参数必须要有默认值 3 function test(x,y="world"){ 4 console.log(x,y) 5 } 6 test('hello');//hello world 7 test('hello',"kill");//hello kill 8 9 } 10 { 11 ... 阅读全文
posted @ 2018-06-21 17:22 chenlw101 阅读(140) 评论(0) 推荐(0)
es6基础(6)--数组扩展
摘要:1 //数组扩展 2 { 3 let arr=Array.of(3,4,6,7,9,11);//可以是空 4 console.log('arr=',arr);//[3,4,6,7,9,11] 5 } 6 { 7 //Array.from把伪数组或者集合变为数组 8 let p=document.querySelectorAll('p'); 9 ... 阅读全文
posted @ 2018-06-21 16:10 chenlw101 阅读(128) 评论(0) 推荐(0)
es6基础(5)--数值扩展
摘要:1 { 2 //Number.isFinite数字是有尽的 3 console.log(Number.isFinite(15));//true 4 console.log(Number.isFinite(NaN));//false 5 console.log(Number.isFinite('true'/0));//false 6 co... 阅读全文
posted @ 2018-06-21 15:39 chenlw101 阅读(106) 评论(0) 推荐(0)
es6基础(4)--字符串扩展
摘要:1 //字符串扩展 2 { 3 console.log('a','\u0061'); 4 console.log('s','\u20BB7');//超过了0xffff 5 6 console.log('s','\u{20BB7}');//如果超过就用{}包裹 7 8 } 9 { 10 //es5中 11 let s='𠮷'; 12 ... 阅读全文
posted @ 2018-06-21 15:08 chenlw101 阅读(110) 评论(0) 推荐(0)
es6基础(3)-正则扩展
摘要:1 //正则扩展 2 { 3 let regex=new RegExp('xyz','i'); 4 let regex2=new RegExp(/xyz/i); 5 6 console.log(regex.test('xyz123'),regex2.test('xy')); 7 //后面的修饰符i覆盖原来的ig修饰符 8 let rege... 阅读全文
posted @ 2018-06-21 14:09 chenlw101 阅读(94) 评论(0) 推荐(0)
es6基础(2)--解构赋值
摘要:1 //解构赋值 2 3 { 4 let a,b,rest; 5 [a,b]=[1,2]; 6 console.log(a,b); 7 } 8 //数组解构赋值 9 { 10 let a,b,rest; 11 [a,b,...rest]=[1,2,3,4,5,6]; 12 console.log(a,b,rest); 13 } ... 阅读全文
posted @ 2018-06-21 13:33 chenlw101 阅读(133) 评论(0) 推荐(0)
es6基础(1)--声明
摘要:1 function test(){ 2 //let只在块作用域有效 3 for(let i=1;i<3;i++){ 4 console.log(i); 5 } 6 //es6严格模式,变量未声明,不可以用 7 //console.log(i); 8 //let 里面不可以声明两个相同的变量 9 let a... 阅读全文
posted @ 2018-06-21 11:35 chenlw101 阅读(84) 评论(0) 推荐(0)