Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > variable and function visibility problem

Reply
Thread Tools

variable and function visibility problem

 
 
[RaZoR]
Guest
Posts: n/a
 
      09-02-2003
hello everybody,

here is my problem: I would like to have scripts that work in parallel.
all of them are controlled and run by main script, namely main.js.
main.js creates the InternetExplorer object (called oIEPipe) with many
variables. oIEPipe is used as a channel that all scripts communicate
through with one another.

0) I have defined an object MyObj as follows:

function MyObj () {
mo = new Object();
var Value;
var setValue = function(arg) { Value = arg; }
var getValue = function() { return Value; }
mo.setV = setValue;
mo.getV = getValue;
return mo;
}

this definition is loaded into main script at the beginning. then main
script creates the communication channel oIEPipe and creates an Array
there. then it runs one of the clients. client looks for the channel
window, finds it and starts to communicate with main script and other
clients through it.

1) when I write in main script:

//definition of MyObj is already loaded
oIEPipe.document.Script.MyArray = new Array();
oIEPipe.document.Script.MyArray[0] = new MyObj();
oWSH.Run("client.js", 2, true);

then client.js sees the object MyObj at MyArray[0] and can execute
(since oIEPipe window has been found) the following statements:

//inside client.js: oIEPipeWindow points to oIEPipe in main script
oIEPipeWindow.document.Script.MyArray[0].setV(3.14159);
oIEPipeWindow.document.Script.MyArray[0].getV();

1A) these changes above are visible when client finishes its work and
returns control to main script, so the latter one can execute
successfully for example:

//in main script, after client finishes
oIEPipe.document.Script.MyArray[0].getV();

And here comes the problem:

but when I write in main script:

//definition of MyObj is or is not loaded
oIEPipe.document.Script.MyArray = new Array();
oWSH.Run("client.js", 2, true);

and create all MyObj objects in client:
//definition of MyObj is already loaded here: client script
oIEPipeWindow.document.Script.MyArray[0] = new MyObj();

then MyArray[0] is visible for client, client can call its
functions, set variables etc. thats ok. but after returning to main
script execution similar to 1A) fails and ends with error:

main.js: the remote server machine does not exist or is unavailable,
code: 800A01CE

I thought that this is because Value is not visible as a part of mo. so
I changed the definition of MyObj() as follows:

function MyObj () {
mo = new Object();
mo.Value;
mo.setValue = function(arg) { mo.Value = arg; }
mo.getValue = function() { return mo.Value; }
return mo;
}

now all functions and variables have the "public" status and are visible
outside. (are they? -- please, correct me if I'm wrong). but it still
ends with error message when returning control to main.js

Is there any solution that allows the following plan of execuion:
main creates channel oIEPipe;
main creates array: oIEPipe.document.Script.myArray = new Array();
main calls client.js;
client.js finds oIEPipe and myArray there;
if some condition is met
client.js creates myArray[sizeofMyArray] = new MyObj();
or
client.js creates its own object ClientObj = MyObj()
and then executes a function AddToArray(MyArray, ClientObj)
client.js calls functions of MyArray[sizeofMyArray] (which is
an MyObj object now), sets values etc.
client returns control to main script
main sees all the changes and can execute MyArray[i] functions
created as part on an object in client.js

I would like all variables and functions being "private" in MyObj()
object if possible and accessible only through priveleged functions like
MyArray[i].getV()

Is is possible to implement? Please correct me if my thinking is wrong
somewhere.

I would greatly appreciate any sugestions and help..

regards,
[RaZoR]





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Templates, inheritance and variable visibility ajhietanen@gmail.com C++ 8 04-04-2009 08:01 AM
visibility of variable rahul8143@gmail.com C Programming 14 09-27-2005 08:05 PM
How do I make a table cells visibility depend on a session variable? COHENMARVIN ASP .Net 2 09-12-2005 08:09 PM
Variable Scope / Visibility / Caching Problem Steve Wark ASP .Net 1 05-23-2005 12:36 PM
Variable Scope / Visibility Steve Wark ASP .Net 0 05-23-2005 12:00 PM



Advertisments