es6继承和数据类型

es6数据类型

es6继承

 <script>

        /* 构造函数 */

        // function Person(name,age){

        //     this.name = name;

        //     this.age = age;

        //     this.eat = function(){

        //         document.write('我会吃烧烤')

        //     }

        // }

        class Person{

            constructor(name,age){

                this.name = name;

                this.age = age;

            }

            /* 静态方法 */

            static kaiche(){

                document.write(`公主会开车`)

            }

            eat(){

                document.write(`${this.name}--${this.age}--${this.sex}`)

            }

        }

        /* 构造函数调用了自己的静态方法 */

        /* 静态方式 只能构造函数自己的调用 实例化对象不可以调用 */

        // Person.kaiche();

        // new Person().kaiche();不可以

        class Student extends Person{

            constructor(name,age,sex){

                /* super就代表父类(Person) */

                super(name,age)

                this.sex = sex;

            }

            eatA(){

                super.eat()

            }

        }

        let stu = new Student('公主',20,'女')

        console.log(stu);

        stu.eatA();

        let p = new Person('龚助',22)

        console.log(p.eat())

    </script>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容