ES6课程---5、形参默认值
一、总结
一句话总结:
形参默认值就是给函数的形参指定默认的参数,如果传参数进来了,就用传进来的参数,如果没有传递参数进来,就用默认值,比如 function Point(x=0,y=0) {}
function Point(x=0,y=0) { this.x=x; this.y=y; } let point=new Point(12,23); console.log(point); let point1=new Point(); console.log(point1);
二、形参默认值
博客对应课程的视频位置:5、形参默认值
https://www.fanrenyi.com/video/24/200
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>形参默认值</title> 6 </head> 7 <body> 8 <!-- 9 10 --> 11 <script> 12 //定义一个点的坐标的构造函数 13 function Point(x=0,y=0) { 14 this.x=x; 15 this.y=y; 16 } 17 let point=new Point(12,23); 18 console.log(point); 19 let point1=new Point(); 20 console.log(point1); 21 22 </script> 23 </body> 24 </html>