variable question ??

B

bscofield

I have 4 *.js files that I am referring to with <script src=*.js></script>

call the files A, B, C, and D.

From file "A" I can view and use variable "Data1" from file "D".
From file "B" I CANNOT view nor use variable "Data1" from file "D".

What's up with that?

Any ideas...?
 
B

Brian Genisio

bscofield said:
I have 4 *.js files that I am referring to with <script src=*.js></script>

call the files A, B, C, and D.

From file "A" I can view and use variable "Data1" from file "D".
From file "B" I CANNOT view nor use variable "Data1" from file "D".

What's up with that?

Any ideas...?

When it comes to scripting, all of your includes are sequential.

This means that A is loaded and executed before B is, which is loaded
before C is, etc.

If the code is written so it is executed inline in B, then it cannot see
something declared in D. If the code is written so it is executed as an
event in A, then there is a good chance D has been loaded, and it exists.

Here is an example of what I mean... immagine the 4 scripts are all inline:

///// File A.js
function test() {
alert(JunkFromD);
}

///// File B.js
alert(JunkFromD);

///// File C.js
/// whatever

///// File D.js
var JunkFromD = "THIS IS A TEST";

......

<button onClick="test()">Click Me</button>


So, in this case, a the function test() in file A.js does not get
called, until after D.js is defined, so JunkFromD exists. (In the Button
click)

In file B.js, you are executing the statement immediately, so JunkFromD
has not yet been created.


Note, that this is just a Wild Ass Guess to what the issue is. Without
seeing the code, it is almost impossible to tell for sure.

I hope this helps,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top