es6 语法 (函数扩展)
生活随笔
收集整理的這篇文章主要介紹了
es6 语法 (函数扩展)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//函數參數默認值(more值后不能有參數)
{function test(x,y = 'world'){console.log('默認值',x,y); }test('hello');// hello worldtest('hello','kill'); //hello kill
}
//作用域概念
{let x = 'test';function test2(x,y = x){console.log('作用域',x,y);}test2(); // undefined undefinedtest2('kill');// kill killfunction test3(c,y=x){console.log('作用域',c,y);}test3();// undefined test
}//參數
{function test3(...arg){for(let v of arg){console.log('rest',v); }}test3(1,2,3,4,'a'); // 1,2,3,4,a
}//擴展運算符
{console.log(...[1,2,4]); //1,2,4console.log('a',...[1,2,4]); //a,1,2,4
}// 箭頭函數
{
//函數名 參數 箭頭 返回值let arrow = v => v*2;let arrow2 = () => 5;console.log('arrow',arrow(3)); //6console.log(arrow2); //function arrow2 (){ return 5};
}//偽調用
{function tail(x){console.log('tail',x); //123
}function fx(x){return tail(x);}fx(123);
}
更多專業前端知識,請上 【猿2048】www.mk2048.com
?
更多專業前端知識,請上 【猿2048】www.mk2048.com
總結
以上是生活随笔為你收集整理的es6 语法 (函数扩展)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js正整数正则表达式
- 下一篇: 将一个实体转换成 Url 参数的形式 ?