<script>
window.onload = function () {
function add(a) {
if (!a) {
//a=null或a=unfind...
a = 1;
}
console.log(a);
}
add();
//es6 函数默认值
function bdd(a = 1) {
console.log(a);
}
bdd();
bdd(5);
//es6 之前可变长度参数
add([1, 2]);
//es6 可变长度参数
function ss(...a) {
console.log(a);
}
ss(1, 2, 3, 4);
//es6 传入参数解构
let nums = {
x: 1,
y: 2
};
function xx({ x, y }) {
console.log(x + y);
}
xx(nums); //nums里面的参数必须和函数里的参数保持一致。。。。。
//箭头函数 lambda表达式 =>
function yy(a, b) {
return a + b;
}
console.log(yy(1, 2));
//es6箭头函数
let yyy = (a, b) => a + b; //单行
console.log(yyy(1, 2));
let yyyy = (a, b) => {
return a + b;
};
console.log(yyyy(1, 2));
};
</script>
es03函数优化
最新推荐文章于 2024-10-08 14:23:59 发布