ES6 - 基础学习(14): 函数的扩展

函数参数的扩展

参数的默认值

// ES6之前,方法不能为参数直接指定默认值,只能通过参数判定的方式,为参数设置默认值。
function testFunc(x, y) {
    y = y || 'ES6';
    console.log(x, y);
}

testFunc('Welcome to');                  // Welcome to ES6
testFunc('Welcome to', 'China');         // Welcome to China
testFunc('Welcome to', '');              // Welcome to ES6

猜你喜欢

转载自www.cnblogs.com/donghuang/p/12423147.html
今日推荐