ES6基本语法

不定参数

<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MaGgIeOo0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值