不定参数
<body>
<script>
function show(...a){
console.log(a.length)
}
show();
show(1,2,3);
show(1);
function show(a,...b){
console.log(b.length)
}
show(11,1);
show(1,2,3);
show(1);
</script>
</body>
定义方法简写
<body>
<script>
let stu = {
"show":function(){
console.log( "这是最原始写法1");
}
}
stu.show()
let stu1 = {
show:function(){
console.log( "这是最原始写法2");
}
}
stu1.show()
let stu2 = {
show(){
console.log( "这是简写法");
}
}
stu2.show()
</script>
</body>
对象扩展运算
<script>
let stu = {"name":"mary","sex":"男"}
let stuCopy = {...stu};
console.log(stuCopy)
let str = {"age":23,"email":"123@q.com"}
let copy = {...stu,...str}
console.log(copy)
</script>
函数的默认参数
<script>
function show(a=1,b=9){
return a+b;
}
console.log(show())
console.log(show(2))
console.log(show(2,4))
</script>
解构赋值运算
<script>
//数组解构
let num=1,a="qaw",flag=true;
let [num1,a1,flag1] = [1,"qaw",true]
console.log(num1,a1,flag1)
//对象解构
let student = {"sname":"张三","sex":"男"}
console.log(student.sname,student.sex)
let sname = student.sname
let sex = student.sex
console.log(sname,sex)
</script>
模板字符串
<script>
let name = "mary";
let str = "helllo"+name;
console.log(str);
let str1 =`hello ${name}`;
console.log(str1)
let str2 = `hellow
world`
console.log(str2)
function show(){
return "mary";
}
let str3 = "你好"+show();
console.log(str3)
let str4 = `你好${show()}`
console.log(str4)
</script>
声明对象简写
<script>
let name="mary",sex="女";
let student ={"sname":name,"ssex":sex}
let student1 = {name,sex}
console.log(student)
console.log(student1)
</script>
4万+

被折叠的 条评论
为什么被折叠?



