独生子 [英] Singleton

查看:82
本文介绍了独生子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


你怎么做一个单身访问课程?


你知道更好的方法吗?


var singletonClass =(function()

{

//私有变量

var instance = null;


//私人构造函数

函数myClass()

{

//。 ..

}


返回新功能()

{

this.constructor = null ;


this.getInstance = function()

{

if(!instance)

{

instance = new myClass();

instance.constructor = null;

}


返回实例;

}

}

})();

Hi guys,

how do you make a singleton access class?

Do you know a better way of this one:

var singletonClass = (function( )
{
// Private variable
var instance = null;

// Private Constructor
function myClass( )
{
//...
}

return new function( )
{
this.constructor = null;

this.getInstance = function( )
{
if( ! instance )
{
instance = new myClass( );
instance.constructor = null;
}

return instance;
}
}
})( );

推荐答案

2008年5月7日星期三10:42:51 +0200,Ugo< pr ***** @ nospam.itwrote:
On Wed, 7 May 2008 10:42:51 +0200, Ugo <pr*****@nospam.itwrote:

>大家好,

你怎么做单身人士访问课?

你知道吗?这个方法:

var singletonClass =(function()
{

//私有变量

var instance = null ;


//私人构造函数

函数myClass()

{

// .. 。

}


返回新功能()

{

this.constructor = null;


this.getInstance = function()

{

if(!例子)

{

instance = new myClass();

instance.constructor = null;

}


返回实例;

}

}
})();
>Hi guys,

how do you make a singleton access class?

Do you know a better way of this one:

var singletonClass = (function( )
{
// Private variable
var instance = null;

// Private Constructor
function myClass( )
{
//...
}

return new function( )
{
this.constructor = null;

this.getInstance = function( )
{
if( ! instance )
{
instance = new myClass( );
instance.constructor = null;
}

return instance;
}
}
})( );



Pure qui? :-))

se ti vede ZERO ...

ciao

Pure qui? :-))
se ti vede ZERO...
ciao


你知道更好的方法吗?这一个:




改变这个:

* *返回新功能()


到此:

返回功能()


;-)
Do you know a better way of this one:
Yes

change this:
* *return new function( )

to this:
return function( )

;-)


开5月7日,11:06 * am,RoLo< roloswo ... @ gmail.comwrote:
On May 7, 11:06*am, RoLo <roloswo...@gmail.comwrote:

你知道更好吗?这个方式:
Do you know a better way of this one:






改变这个:

** *返回新的功能()


到此:

* *返回功能()


;-)


Yes

change this:
** *return new function( )

to this:
* * return function( )

;-)



ok ...抱歉,我读过你的代码..你可以忽略我以前的评论。

ok... sorry, I over read you code.. you can ignore my previous comment.


这篇关于独生子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆