js class生成 构造函数

class Test {

person(e){
    this.e = e
}
create(e){
    this.ps = new this.person(e)
}

}
为什么提示 this.person is not a constructor

阅读 2.1k
2 个回答

不知道是不是你要的

class Person {
            constructor(name) {
                this.name = name;
            }

            sayHello() {
                console.log(`我是${this.name}`);
            }
        };

        class Student extends Person {
            constructor(name,school) {
                super(name);
                this.school = school;
            }

            printSchoolName() {
                console.log(`我在${this.school}读书`);
            }
        };


        let kun = new Student('kun', 'hha');
        console.log(kun)
        kun.sayHello();
        kun.printSchoolName();
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题