ES6参考---形参默认值
一、总结
一句话总结:
形参的默认值:当不传入参数的时候默认使用形参里的默认值function Point(x = 1,y = 2){}
function Point(x = 1,y = 2) {
this.x = x;
this.y = y;
}
二、形参默认值
博客对应课程的视频位置:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>08_形参默认值</title> 6 </head> 7 <body> 8 <!-- 9 * 形参的默认值----当不传入参数的时候默认使用形参里的默认值 10 function Point(x = 1,y = 2) { 11 this.x = x; 12 this.y = y; 13 } 14 --> 15 <script type="text/javascript"> 16 //定义一个点的坐标 17 function Point(x=12, y=12) { 18 this.x = x; 19 this.y = y; 20 } 21 let point = new Point(25, 36); 22 console.log(point); 23 let p = new Point(); 24 console.log(p); 25 let point1 = new Point(12, 35); 26 console.log(point1); 27 28 </script> 29 30 </body> 31 </html>