12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // function foo(a,b){
- // if(a && b){
- // console.log(a+b);
- // }else{
- // console.log("缺少参数");
- // }
- // }
- // foo(1)
- // ES6 新增默认值 如果参数有值 就用参数的值 如果没有值 就用默认值
- // function foo(a=0,b=0){
- // console.log(a+b);
- // }
- // foo(1,2)
- // function foo(a,b,c = 0){
- // console.log(a+b+c);
- // }
- // foo(1,2,3)
- // 函数length 属性 代表形参的个数 且没有默认值
- // console.log(foo.length);
- // function foo(){};
- // let foo = function(){};
- // ES6 新增箭头函数 语法更加简洁
- // let foo = () => {};
- // let foo = (a,b) => {
- // console.log(a+b);
- // }
- // foo(1,2);
- // 当箭头函数省略大括号时 会默认返回值 返回箭头后边的第一条语句;
- // let foo = (a,b) => a+b;
- // console.log(foo(1,2));
- // function foo(a,b){
- // return a+b;
- // }
- // console.log(foo(1,2));
- // function foo(...arg){
- // console.log(arg);
- // }
- // foo(1,2,3);
- // function foo(){
- // console.log(arguments[0]);
- // }
- // foo(1,2,3,4,5)
- // let foo = () => {
- // console.log(arguments);
- // }
- let foo = (...arg) => {
- console.log(arg);
- }
- foo(1,2,3,4,5);
- </script>
- </body>
- </html>
|