Is this something with javascript; or is it something else I'm doing wrong.
file1.js
var collection = new Object(); collection.foo = new Array(1, 2, 3);
file 2.js
var someClass = new Class({ bar : function() { alert(collection.foo.length); } });
index.html
<script type="text/javascript" src="file1.js"></script> <script type="text/javascript" src="file2.js"></script> <script type="text/javascript"> var x = new someClass(); x.bar(); //cannot find collection </script>
So I tried another approach:
file1.js
collection.foo = new Array(1, 2, 3);
file 2.js
var someClass = new Class({ bar : function() { alert(collection.foo.length); } });
index.html
<script type="text/javascript"> var collection = new Object(); </script> <script type="text/javascript" src="file1.js"></script> <script type="text/javascript" src="file2.js"></script> <script type="text/javascript"> var x = new someClass(); x.bar(); //cannot find collection.foo </script>
I'm using mooTools (where the Class object comes from) if you think that matters.
Update: I simplified it for posting the example, but the x.bar() is part of a click event for another method. But after some alert() testing I discovered file1 was not actually being executed. It's actually a .axd file being send with the text/javascript contenttype, so I'm not sure why - I'll have to investigate tommorrow.
And yes, the tags will be at the bottom. file1 is an annoying large javascript file, which is why it's separated out - the goal is to have to cached on the client as much as humanly possible. It's an .axd file because it generated from the database (Ref data) and I set the expires, compression, contenttype, and cachability explicitly.
Update: After more fiddling, I figured out there was an error in the data generated that firebug wasn't catching; and this was just a bug, not some deep technical problem. As such; closing.