ES6 class 基本使用

<!DOCTYPE html>
<html lang="zh">

    <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>ES6 class</title>
    </head>

    <body>
        <script type="text/javascript">
            class Person {
                //实例方法
                constructor(name) {
                    this.name = name;
                }
                //原型链方法
                sayName() {
                    console.log(this.name)
                }
            }
            //不存在变量提升
            let tom = new Person('tom');
            tom.sayName();
        </script>
    </body>

</html>

猜你喜欢

转载自www.cnblogs.com/mengfangui/p/9752968.html