码迷,mamicode.com
首页 > Web开发 > 详细

js 继承

时间:2020-05-04 13:11:21      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:class   student   this   style   ext   pre   div   new   cto   

//父类
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 继承

标签:class   student   this   style   ext   pre   div   new   cto   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!