首页 > Web开发 > 详细

js 继承

时间:2020-05-04 13:24:38      阅读:40      评论:0      收藏:0      [点我收藏+]
//父类
class Person{
    constructor(name) {
        this.name = name
    }
    eat(){
        console.log(`${this.name} eat something`)
    }
}

//子类
class Student extends Person{
    constructor(name,number) {
        super(name);
        this.number = number
    }
    sayHI(){
        console.log(`姓名 ${this.name} 学号 ${this.number} `)
    }
}

//实列
const std = new Student(‘周瑜‘,333)
std.sayHI()
std.eat()

 

//父类
class Person{
constructor(name) {
this.name = name
}
eat(){
console.log(`${this.name} eat something`)
}
}

//子类
class Student extends Person{
constructor(name,number) {
super(name);
this.number = number
}
sayHI(){
console.log(`姓名 ${this.name} 学号 ${this.number} `)
}
}

//实列
const std = new Student(周瑜,333)
std.sayHI()
std.eat()

js 继承

原文:https://www.cnblogs.com/yangxuming/p/12825977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!