本文實例講述了ES6知識點整理之函數(shù)對象參數(shù)默認值及其解構(gòu)應(yīng)用。分享給大家供大家參考,具體如下:
同函數(shù)數(shù)組參數(shù)一樣,函數(shù)的對象參數(shù)的默認值和解構(gòu)過程整理
函數(shù)對象參數(shù)的默認值與解構(gòu)的形式
此處使用箭頭函數(shù)來處理 :
(({x,y})=>{ console.log(x, y); // // undefined undefined})({});(({x=1,y=2})=>{ console.log(x,y); // 1 2})({});(({x=3, y=4}={})=>{ console.log(x,y); // 3 4})();注意傳值解析中可能的陷阱
function test4({x,y}={x:100,y:200}) { console.log(x,y);}test4({}); // undefined undefinedtest4(); // 100 200對象參數(shù),數(shù)組參數(shù)和字符參數(shù)的結(jié)合使用
function test({x=1,y=2,z=3}={}, [a=11,b=22,c=33]=[],name='Joh') { console.log(x,y,z,a,b,c,name);}test(); // 1 2 3 11 22 33 "Joh"希望本文所述對大家JavaScript程序設(shè)計有所幫助。
新聞熱點
疑難解答