Vue第一篇 ES6的常用语法

01-变量的定义

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // var somedody;
    // console.log(somebody);
    // var somebody = "lingruizhi";
    // 变量的提升
    function func() {
        // console.log(somebody);
        if(1){
            let somebody = "hexin";
        }
    }
    func();
    let age = 81;
    age = 18;

    const girl = "wangshuang";
    // girl = "llal";
</script>

</body>
</html>

02- 模板字符串

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <h1>文周的爱好</h1>

</div>

<script>
   // 给div添加文本
   let ele = document.getElementById("app");
   ele.innerText = "hello";
   let hobby1 = "翻车";
   let hobby2 = "背诗";
   let hobby3 = "看女主播";
   ele.innerHTML = `<ul>
        <li>${hobby1}</li>
        <li>${hobby2}</li>
        <li>${hobby3}</li>
    </ul>`
    // ele.innerHTML = "<ul><li>"+ ""+ "</li></ul>"


</script>
</body>
</html>

03-函数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // 箭头函数
    // this  当前函数最近的调用者
    // 取决于当前的上下文环境
    function aa() {
        console.log(this)
    }
    aa();
    let obj1 = {
        a: 1,
        func: aa
    }
    obj1.func();
    let obj2 = {
        obj1: obj1,
        a: 2
    }
    obj2.obj1.func();

    function myfunc(x) {
        return x+1
    }
    let fun2 = x => x+1;
    console.log(fun2(5))

</script>
</body>
</html>

04-数据的解构

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let obj = {
        a: 1,
        b: 2,
        x: 3,
        y: 4
    };
    let hobby = ["吹牛", "特斯拉", "三里屯"];

    let {x, y} = obj;
    let [hobby1, hobby2, hobby3] = hobby;

    console.log(x);
    console.log(y);
    console.log(hobby1);
    console.log(hobby2);
    console.log(hobby3);


</script>
</body>
</html>

05-类的定义

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    class Animal {
        constructor(){
            this.type = "animal"
        };
        say(){
            console.log("ao~~~~")
        }
    };
    class Dog extends Animal {
        // 子类没有this
        constructor(){
            super()
            // 用super方法拿到父类的this
            this.type = "dog"
        }
        say(){
            console.log("wang~~~~")
        }
    }
    let dog = new Dog();
    console.log(dog.type);
    dog.say()

    // class Animal():
    //     def __init__


</script>
</body>
</html>

 

  总结:

ES6的常用语法
	变量的定义
		-- var  变量的提升 函数作用域以及全局作用域
 		-- let  块级作用域  {}
		-- const  常量  不可以修改
	模板字符串
		语法 ``
		变量 ${}
	箭头函数
		类比Python的匿名函数
		this
			-- 普通函数的this取决于函数最近的调用者
			-- 箭头函数的this取决于当前上下文的环境
	数据的解构
		-- 解构对象 let {key, key} = obj
		-- 解构数组 let [x, y, x] = array
	类的定义
		-- 定义类 class
		-- 构造方法 constructor
		-- 继承 extends
		-- 子类没有this 需要用super方法来找到父类的this

  

  

  

转载于:https://www.cnblogs.com/cavalier-chen/p/10096276.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值