[Project_owners] Global listeer

InBasic inb.cor at gmail.com
Wed Nov 21 11:24:19 PST 2007


Hi Joe,

There are some problems with your variable definition
Do these steps:


   1. as Nickolay said, define variable in this way,

//Component constructor
function MyComponent() {
this.wrappedJSObject = this;  //in order to access the JS object directly,
you must modify the component.
this.MyVar = "hello";
}

   1. in Component prototype add this line too

MyVar: null,

now you can access to read or write to your variable Globally like this

var myService = Components.classes["@mozilla.doslash.org/test/component;1"]
                     .getService().wrappedJSObject;

//Write
myService.MyVar="New String";
//or Read
dump(myService.MyVar)

InBasic,


On Nov 21, 2007 2:40 PM, Nickolay Ponomarev <asqueella at gmail.com> wrote:

> On Nov 21, 2007 9:38 AM, joe ertaba <belaviyo at gmail.com> wrote:
> > As in :
> >           http://developer.mozilla.org/en/docs/wrappedJSObject
>
> You didn't post any of the wrappedJSObject-related code from that
> page. I hoped that page was pretty clear, but if you can suggest
> improvements, please do.
>
> > myService.QueryInterface(Components.interfaces. nsIObserver);
> > dump(myService.observe)
> >
> > it works perfectly and output is " function observe() { [native code] }"
> >
> ..which is defined in the nsIObserver interface, so is known to the
> XPConnect wrapper you have in myService. The JS object properties that
> are not part of any interface the wrapper knows about are not visible
> to your code working with the wrapper.
>
> > but when i add some variable to code like:
> >
> > MyComponent.prototype = {
> >
> > ...
> > MyVar:'hello',
>
> BTW, I would instead define the var in the MyComponent constructor,
> it's probably closer to what you need:
>
> function MyComponent() { this.myVar = "hello"; }
>
> Nickolay
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.mozdev.org/pipermail/project_owners/attachments/20071121/ae0cf4e6/attachment-0001.html 


More information about the Project_owners mailing list