JavaScript language advanced Tips & Tricks
http://code.google.com/p/jslibs/wiki/JavascriptTips#Singleton_pattern
Java script singleton: http://www.hardcode.nl/subcategory_1/article_526-singleton-examples-in-javascript.htm
var Setting =(function(){
var instantiated;
function init (){
// all singleton code goes here
return {
publicWhatever:function(){
alert('whatever')
},
userID:null,
setUserID:function( id ) {
userID = id;
},
getUserID:function() {
return userID;
}
}
}
return {
getInstance :function(){
if (!instantiated){
instantiated = init();
}
return instantiated;
}
}
})()
Java script singleton: http://www.hardcode.nl/subcategory_1/article_526-singleton-examples-in-javascript.htm
var Setting =(function(){
var instantiated;
function init (){
// all singleton code goes here
return {
publicWhatever:function(){
alert('whatever')
},
userID:null,
setUserID:function( id ) {
userID = id;
},
getUserID:function() {
return userID;
}
}
}
return {
getInstance :function(){
if (!instantiated){
instantiated = init();
}
return instantiated;
}
}
})()
Comments
Post a Comment