其他分享
首页 > 其他分享> > typescript 单例模式

typescript 单例模式

作者:互联网

class Demo{
    private static instance:Demo;
    public constructor(name:string){
  console.log('name:',name)
    }
    public static getinstance(){
        if(!this.instance){
            this.instance= new Demo("Tom")
        }
        return this.instance;
    }
}

Demo.getinstance();
Demo.getinstance();

  

标签:typescript,name,getinstance,Demo,模式,instance,static,单例,public
来源: https://www.cnblogs.com/boye169/p/16350754.html