zoukankan      html  css  js  c++  java
  • ts-类

    class Person {
      // 默认public  
      //private私有,不可访问  
      //protected子类可以访问,外部不可以访问
      // readonly 只可读,不可写
      // static 静态属性 当类的定义与实例状态没有太大关系的时候使用
      protected name:string;
      static stateVal:string[] = ['aaa','bbb'];
      static checkName(a){
        return a instanceof Person
      }
      constructor(name:string){
        this.name = name
      }
      funtest(){
        return `${this.name} is running`
      }
    }
    let person = new Person("aaaa");
    
    console.log(person.funtest())
    
    
    class lili extends Person{
      childTest(){
        return `${this.name} is child`
      }
    }
    let liliclass = new lili('liliname')
    console.log(liliclass.funtest())
    console.log(liliclass.childTest())
    
    console.log(Person.checkName(liliclass))
    
    class lilei extends  Person{
      constructor(name){
        super(name)
      }
      funtest(){
        return `${this.name} is funtestReload`
      }
    }
    let lileiclass = new lilei('lilei')
    console.log(lileiclass.funtest())
    

      

  • 相关阅读:
    N!的位数
    c语言memset()函数
    通宵教室(ACM水题)
    欧拉函数+素数筛
    快速幂+大数取模
    观光浏览
    插入类排序(直接插入排序)
    showDoc使用方法
    $_POST与input('post.')区别
    “三日”面试官心得
  • 原文地址:https://www.cnblogs.com/chenlw/p/14116333.html
Copyright © 2011-2022 走看看