/***
- es6
- */ { //let [foo, [[bar], baz]] = [1, [[2], 3]];
//console.log(foo) } //{ //let [x,,y]=[1,2,3];
//console.info(x); //} { let name ='shulong';
let age= '23';
// console.log(${name}
,'名字') } { function add(...add){ let sum = 0;
for(let val of add){
sum +=val;
}
return sum;
}
// console.log(add(2,5,3)) } { //箭头函数es6箭头 => 代表大括号 let f =() =>5;
//console.log(f());
let sum = (sum1,sum2='2')=>sum1+sum2;
//console.log(sum(1,2));
//箭头函数对应的是数据整合效果,可以添加复制
} { const full = ({first,last})=>first+'last';
//console.log(full());
} { //sperad ... 参数的运算数组用逗号隔开
function push(array,...items){
array.push(items)
}
let number =[4,38];
//console.log(...number);
} { let birth='2014/10/11';
let Person ={
name:birth
};
//console.log(Person.name);
} { function sayHello(name="world"){
// console.log(`Hello ${name}`);
}
//sayHello();
sayHello('wayou')
} { function add(...x){
return x.reduce((m,n)=>m+n);
}
//console.log(add(1,2,3));
//console.log(add(1,2,3,4,5,6,7,8,9));
} { let person =['wuhan','nanjing','hefen'];
function say (a1,a2,a3){
// console.log(`hi ${a1},${a2},${a3}`);
};
//say(...person);
} { let s = new Set();//添加不了重复的数字
//console.log(s.add(1).add(2).add(3));//{1,2,3}
let y = new Map();
var e = y.set('hello',32);
//console.info(e); //hello=>32
// console.log(y.set(s));
} { let s = new Set();//添加不了重复的数字 let vm = new WeakMap(); vm.set(s,{extra:42}); let a =vm.size === undefined; //console.log(a);
} { //symblos; //console.log(Number.EPSILON);//对数
console.log(Number.isInteger(Infinity));
let acosh = Math.hypot(3,4);
let hypot = Math.acosh(2);
let imul = Math.imul(Math.pow(2,32)-1 , Math.pow(2,32)-2);
// console.log('abcde'.contains('cd')); //true
let as = 'abc'.repeat(3);
Array.from(document.querySelectorAll('*'));
Array.of(1,2,3);
[0,0,0].fill(7,1);
[1,2,3].findIndex(x =>x ==2); //1
//['a','b','c'].values();
// Object.assign(Point,{origin:new Point(0,0)});
let o =1;
let k=2;
let es5={ o:o, k:k }; let es6 = { o, k }; console.log(es5);
console.log(es6);
} { let es5 ={ hello:function(){
console.log('hello')
}
};
let es6 = {
hello(){
console.log('hello');
}
}
console.log(es5.hello());
console.log(es6.hello());
} { let a = 'b'; let es5 = { a:'c', b:'c' }; let es6 = { [a]:'c' }
console.log(es5,es6);
} { // object 新增api // console.log('字符串',Object.is('abc','abc'),'abc'==='abc');
// console.log('数组',Object.is([],[]),[]===[]);
// console.log('拷贝',Object.assign({a:'a'},{b:'b'}));
let test = {k:123,o:456};
//拷贝数组键值对
for(let [key,value] of Object.entries(test)){
//console.log([key,value]);
}
} { //symbol 概念 作用
let Symbol1 =Symbol();
let Symbol2 =Symbol();
console.log(Symbol1===Symbol2);
let a3 = Symbol.for('a3');
let a4 = Symbol.for('a3');
console.log(a3===a4);
} { let a1= Symbol.for('abc');
let obj={
[a1]:'123',
'abc':345,
'c':456
};
// console.log(obj); for(let [key,value] of Object.entries(obj)){
console.log('let ',key,value);
//拿不到[a1]
}
//拿到Symbol
Object.getOwnPropertySymbols(obj).forEach(function(item){
console.log(obj[item]);
});
//拿到key value
Reflect.ownKeys(obj).forEach(function(e){
console.log('ownKeys',e,obj[e]);
})
} { let list = new Set();
list.add(5);
list.add(7);
console.log(list.size);
} { let arr =[1,2,3,4,5,'2']; let list2= new Set(arr); console.log(list2); let sta = ['add','delete','clear','has'];
let list = new Set(sta);
// console.log(list.has('add')); //true
// console.log(list.delete('add'));
// console.log(list);
// console.log(list.clear());//清空
// console.log(list);
// for(let key of list.keys()){
// console.log('keys',key);
// } // for(let value of list.values()){
// console.log('values',value);
// } // for(let [key,value] of list.entries()){
// console.log('en',key,value)
// }
} { // console.log("Number",Number.parseFloat === parseFloat);
// const foo = 'bar';
// const baz = {foo};
//baz // {foo:'bar'}
//const baz ={foo:foo};
// function f(x,y){
// // return {x,y};
// }
// function f(x,y){ // // return {x:x,y:y}; // } // 数据结构横向对比 增 查 改 删
let map = new Map();
let array = []; map.set('t',1);
array.push({t:1});
console.log('map-array',map,array); //查询 let map_exist = map.has('t'); //true
let array_exist = array.find(item=>item.t);
console.log('map_exist',map_exist,array); // 改 map.set('t',2);
array.forEach(item=>item.t?item.t=2:'');
console.log('map-array-modify',map,array); //删除
map.delete('t');
let index = array.findIndex(item=>item.t);
array.splice(index,1);
console.log('map',map,array);
//set array
let set = new Set();
let arr =[]; //增 set.add({name:"shulonghu"});
arr.push({name:'shulonghu'});
console.log('set-updet',set,arr);
//查 let set_ex = set.has({name:'shulonghu'});
let arr_ex = arr.find(item=>item.name);
console.log('set_ex',set_ex,arr_ex);
//改 set.forEach(item=>item.name?item.name=2:'');
arr.forEach(item=>item.name?item.name=2:'');
console.log('set-array',set_ex,arr_ex); //删 set.forEach(item=>item.name?set.delete(item):'');
let indee = arr.findIndex(item=>item.name);
arr.splice(indee,1);
console.log('/set-arr-empty',set,arr); } { //map set obj let item = {t:1} let map =new Map(); let set =new Set(); let Obj ={};
//增
map.set('t',1);
set.add(item);
set.add(item);
map.set('t',1);
Obj['t']=1;
console.info('map-set-obj',Obj,map,set)
//查
console.info({
'map':map.has('t'),
'set':set.has('t'),
'Obj':'t' in Obj //查询
});
//改
map.set('t',2);
item.t=2;
Obj['t']= 2;
console.info('mso-modify',Obj,map,set);
// 删
map.delete('t'); set.delete(item); // delete Obj['t']; console.info('mso-del',Obj,map,set); } //f(1,2);