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())
    

      

  • 相关阅读:
    js中有哪些是循环遍历的方法?
    堆内存和栈内存
    Html5和Css3
    PyCharm IDE 的使用
    python基础语法
    数据挖掘书籍简介
    寄存器-2
    汇编基础
    Std::bind()
    手游页游和端游的服务端框架
  • 原文地址:https://www.cnblogs.com/chenlw/p/14116333.html
Copyright © 2011-2022 走看看