After searching the archives and google this I haven't found a
solution to my problem. I am creating a stand-along xulrunner
application and would like to implement some of my components in
JavaScript as services. So basically I'd like some of my components
to be singleton objects.
From my limited understanding of XPCOM it would seem that I can
create a single instance of my object in my factory and return that
in "createInstance". An example of my thoughts might be better:
var Module = {
firstTime: true,
registerSelf: function (compMgr, fileSpec, location, type) {
//....
},
getClassObject : function (compMgr, cid, iid) {
//....
return this.myFactory;
},
myFactory: {
_instance : null,
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if(!_instance) {
_instance = new MyComponent();
}
return _instance.QueryInterface(iid);
}
},
canUnload: function(compMgr) {
return true;
}
}; // END Module
Is this the way to do it or is there a "best practice" when
implementing JavaScript service components?
Thanks,
Byron
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom