zoukankan      html  css  js  c++  java
  • 2.class、继承、instanceof

    // 父类
    class People{
        constructor(name){
            this.name = name;
        }
        eat(){
            console.log(`姓名 ${this.name} eat something  `)
        }
    }
    // 子类
    class Student extends People {
        constructor(name, number) {
            super(name);
            this.number = number;
            
        }
        sayHi() {
            console.log(`姓名 ${this.name}  ,  学号  ${this.number}  `)
        }
    
    }
    const aaa = new Student('lisi',100)
    console.log(aaa.name)
    console.log(aaa.number)
    aaa.sayHi()
    aaa.eat()

      

    aaa instanceof Student //true
    aaa instanceof People  //true
    aaa instanceof Object  //true
    
    [] instanceof Array //true
    [] instanceof Object //true
    {} instanceof Object //true
    

      

  • 相关阅读:
    ceph部署与问题
    openstack常见问题汇总
    css
    html
    zookeeper
    ZAB协议
    快速排序
    Servlet梳理
    tomcat性能优化梳理
    tomcat梳理
  • 原文地址:https://www.cnblogs.com/chenlw/p/12525812.html
Copyright © 2011-2022 走看看