ECMAScript 6 入门教程—函数的扩展

1、函数参数的默认值

基本用法(ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法。)

		function log(x, y) {
		  if(typeof y==='undefined'){
			  y="world"
		  }
		  console.log(x, y);
		}

ES6 允许为函数的参数设置默认值,即直接写在参数定义的后面。

		function log(x,y="world"){
			console.log(x,y)
		}

 参考:https://mp.weixin.qq.com/s/3ueI4V1A5ZxIKO20ZzoD9Q

猜你喜欢

转载自blog.csdn.net/baidu_39043816/article/details/108507790