2 basic classes used ES6

Expression of class

Strict mode:

  1. In the <script> in the first line write "use strict", indicates that the following code uses strict mode (or the first line in the file js)
  2. Use custom code, using more standardized, run to avoid some strange behavior
  3. Es subsequent Angular Some other characteristics and JS framework, it is required to be run in strict mode
  4. Make more efficient to compile and run the code of
    impact variables
  5. Variable must first declare reuse
  6. You can not use any reserved words / keywords as variable names
  7. Strict mode will not allow users to delete variables (delete)

important point:

  1. In ES6, the default is the strict mode, there is no need to use "use strict" to specify the mode of operation
  2. There is no variable lift
<!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>
Published 98 original articles · won praise 26 · views 7532

Guess you like

Origin blog.csdn.net/weixin_46146313/article/details/104234145
Recommended