码迷,mamicode.com
首页 > 其他好文 > 详细

Egret中的三种单例写法

时间:2016-11-14 02:08:09      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:技术   ros   mic   str   font   size   private   技术分享   style   

1 普通的单例写法



class Single{ private static instance:Single; public static getInstance():Single{ if(this.instance == null){ this.instance = new Single(); } return this.instance; } public run(){ } } Single.getInstance().run();

  

2 Module写法。仿照的Egret中Res资源类写法。

技术分享

 

 技术分享

 

 3 继承BaseClass

class BaseClass {
    public static getInstance():any {
        var Class:any = this;
        if (!Class._instance) {
                Class._instance = new Class();
        }
        return Class._instance;
    }
}

class Single extends BaseClass{
        public run(){
        }
}

Single.getInstance().run();

 

 

Egret中的三种单例写法

标签:技术   ros   mic   str   font   size   private   技术分享   style   

原文地址:http://www.cnblogs.com/gamedaybyday/p/6060424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!