zoukankan      html  css  js  c++  java
  • class类通过extends继承父类

          class Person {
            constructor(name) {
              this.name = name
            }
            publicFn() {
              console.log('公共方法')
            }
          }
          class Student extends Person {
            constructor(name, score) {
              // this.name = name
              super(name)
              this.score = score
            }
            introduce() {
              console.log(`我是${this.name},考了${this.score}分`)
            }
          }
          class Teacher extends Person {
            constructor(name, subject) {
              // this.name = name
              super(name)
              this.subject = subject
            }
            teach() {
              console.log(`我是${this.name},教${this.subject}`)
            }
          }
          const stu = new Student('小明', 100)
          const teac = new Teacher('王老师', '语文')
          console.log(stu)
          stu.introduce()
          stu.publicFn()
          console.log(teac)
          teac.teach()
          teac.publicFn()

  • 相关阅读:
    Adobe Flash Player 设置鼠标点不到允许或者拒绝!
    bzoj2096
    bzoj2789
    LA3353
    poj2594
    bzoj2427
    bzoj1076
    bzoj2818
    bzoj3668
    bzoj2006
  • 原文地址:https://www.cnblogs.com/wuqilang/p/15167450.html
Copyright © 2011-2022 走看看