let json = { '0': 'jspang', '1': '技術胖', '2': '大胖逼逼叨', length:3 } let arr=Array.from(json); console.log(arr)
[...set數據結構]
也能將set數據結構轉化成數組let arr =Array.of(3,4,5,6); console.log(arr);
let arr =Array.of('技術胖','jspang','大胖逼逼叨'); console.log(arr);
let arr=[0,1,2,3,4,5,6,7,8,9]; arr.fill('jspang',2,5); console.log(arr)
let arr=['jspang','技術胖','大胖逼逼叨'] for (let item of arr){ console.log(item); }
let json = { a:'jspang', b:'技術胖' } function fun({a,b='jspang'}){ console.log(a,b); } fun(json);
let arr = ['jspang','技術胖','免費教程']; function fun(a,b,c){ console.log(a,b,c); } fun(...arr);
...arr
這裏用到了擴展操做符,由於擴展操做符內默認執行for...of...
循環將擴展操做符是把數組擴展成單獨的參數,以後才能解構賦值。(由於解構賦值必須解構結構要統一,否則會報錯)let obj={ a:'jspang', b:'技術胖' } console.log('a' in obj); //true
indexOf
方法判斷或者用includes
方法判斷var a = new String; var b = new Number; var c = new Boolean; var d = new Array; var e = new Object; var f= Symbol(); console.log(typeof(d));//Symbol
var jspang = Symbol(); var obj={ [jspang]:'技術胖' } console.log(obj[jspang]);//技術胖 obj[jspang]='web'; console.log(obj[jspang]);//web
var obj1 = {name:'jspang'}; var obj2 = {name:'jspang'}; console.log(obj1.name === obj2.name);//true
var obj1 = {name:'jspang'}; var obj2 = {name:'jspang'}; console.log(Object.is(obj1.name,obj2.name)); //true
console.log(+0 === -0); //true console.log(NaN === NaN ); //false console.log(Object.is(+0,-0)); //false console.log(Object.is(NaN,NaN)); //true
var a={a:'jspang'}; var b={b:'技術胖'}; var c={c:'web'}; let d=Object.assign(a,b,c) console.log(d);
(Set和WeakSet數據結構)[http://jspang.com/2016/06/14/es6001/]html
let state=1; function step1(resolve,reject){ console.log('1.開始-洗菜作飯'); if(state==1){ resolve('洗菜作飯--完成'); }else{ reject('洗菜作飯--出錯'); } } function step2(resolve,reject){ console.log('2.開始-坐下來吃飯'); if(state==1){ resolve('坐下來吃飯--完成'); }else{ reject('坐下來吃飯--出錯'); } } function step3(resolve,reject){ console.log('3.開始-收拾桌子洗完'); if(state==1){ resolve('收拾桌子洗完--完成'); }else{ reject('收拾桌子洗完--出錯'); } } new Promise(step1).then(function(val){ console.log(val); return new Promise(step2); }).then(function(val){ console.log(val); return new Promise(step3); }).then(function(val){ console.log(val); return val; });
class Coder{ name(val){ console.log(val); } } let jspang= new Coder; jspang.name('jspang');
class Coder{ name(val){ console.log(val); return val; } skill(val){ console.log(this.name('jspang')+':'+'Skill:'+val); } } let jspang= new Coder; jspang.name('jspang'); jspang.skill('web');
class Coder{ name(val){ console.log(val); return val; } skill(val){ console.log(this.name('jspang')+':'+'Skill:'+val); } constructor(a,b){ this.a=a; this.b=b; } add(){ return this.a+this.b; } } let jspang=new Coder(1,2); console.log(jspang.add());
class htmler extends Coder{ } let pang=new htmler; pang.name('技術胖');