6.面向对象

class (es6引入)

1.定义一个类属性方法

class Student{
            name;
            constructor() {    //constructor构造器
                this.name=name
            }
            hello(){
                alert('hello');
            }
    var xiaohong=new Student("xiaohong");
    var xiaoming=new Student("xiaoming");

2.继承 

class Student{
            name;
            constructor(name) {
                this.name=name
            }
            grade(){
                alert(name+"是一名小学生")
            }
        }
        class Pupil extends Student{
            constructor(name,grade) {
                super(name);
                this.grade=grade;
            }
            MyGrade(){
                alert("是一个小学生");
            }

        }

 

posted @ 2022-07-29 20:03  吾辈皆喜黑丝  阅读(16)  评论(0)    收藏  举报