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

问题描述

大家好,


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


你知道更好的方法吗?


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

推荐答案



Pure qui? :-))

se ti vede ZERO ...

ciao

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








改变这个:

** *返回新的功能()


到此:

* *返回功能()


;-)


Yes

change this:
** *return new function( )

to this:
* * return function( )

;-)



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

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


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

10-28 12:14