ES6 类的基本使用2

类的表达式

严格模式:

  1. 在 < script > 中第一行写"use strict",表明下面的代码使用严格模式(或者是js文件中第一行)
  2. 使用代码的定义,使用更加规范, 避免一些诡异的运行行为
  3. 在后续的Es特性和一些Angular等JS框架中,要求必须在严格模式下运行
  4. 使代码的编译和运行更加高效
    对变量的影响
  5. 变量必须要先声明再使用
  6. 不可以使用任意保留字/关键字作为变量名
  7. 严格模式不再允许用户删除变量 ( delete )

注意点:

  1. 在ES6中,默认的就是严格模式,所以不需要使用 “use strict” 来指定运行模式
  2. 不存在变量提升
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表达式</title>
</head>
<body>
    
    <script>

    {
        //属性表达式
        let shopping = "shop";
        class Person{
            constructor(sex) {
                this.sex = sex;
                this.hobby = "女";
            }

            [shopping](){
                console.log("一个省钱的春节");
            }
        }
       
        let person = new Person();
        person.shop();  
    }
    
    {
        // Class 表达式
        const MyClass = class Me {

        }
    }    
    </script>
</body>
</html>
发布了98 篇原创文章 · 获赞 26 · 访问量 7532

猜你喜欢

转载自blog.csdn.net/weixin_46146313/article/details/104234145