[Project_owners] Global listeer

Eric H. Jung eric.jung at yahoo.com
Wed Nov 21 06:34:48 PST 2007


--- joe ertaba <belaviyo at gmail.com> wrote:

> As in :
>           http://developer.mozilla.org/en/docs/wrappedJSObject,
> when i use this code:
>           http://forums.mozillazine.org/viewtopic.php?p=1694347#1694347
> 
> var myService =  Components.classes["@mozilla.doslash.org/test/component;1
> "].getService();
> myService.QueryInterface(Components.interfaces.*nsIObserver*);
> dump(myService.observe)
> 
> it works perfectly and output is "function observe() { [native code] }"
> 
> but when i add some variable to code like:
> 
> MyComponent.prototype = {
> ...
> MyVar:'hello',
> ....
> }
> 
> then when i use above code again it works but the below code does not work
> 
> dump(myService.MyVar)  >>  undefined
> 
> maybe this problem cause because *nsIObserver ?*
> 

Yes, it is because of that. Why are you QueryInterface'ing for nsIObserver? Just do:

var myService =  Components.classes["@mozilla.doslash.org/test/component;1"].getService();
myService.wrappedJS.hello = "world";
dump(myService.wrappedJS.hello + "\n");



More information about the Project_owners mailing list