views:

41

answers:

2

I have 2 .js file, each contain the SAME large array or value (price list) Now i have to get the 2 array exactly the same... not good i like to have another .js file that will execute the array load into any function i like

The way i approch the problem, i defining variable, and executing a function loading value into those... dont work...

What is the proper way to have one list of value in the array, and invoking a function to load it

thanks

+1  A: 

This is what I understand regarding your problem (correct me if I am wrong)

File1.js

var arrayList = [ ........  ]; 

File2.js

var arrayList = [ ........  ];

You want to create a common file which contains this arrayList and it should be accessible from both files. If you are thinking that you need to "include" the common file in both files, you wouldnt need to. Just reference the new file in the html before both these files by the regular script tag and you are good to go.

This unfortunately makes the variable global. I would prefer if you keep all such variables under a single top level variable like so :

var Global = {arrayList : [.........], CONST_SOME_STRING: "fajlsdkfja"};

and then accessing it from the files as Global.arrayList[] etc

Ravindra Sane
i alway though a GLOBAL was a bad thing.. but will try your code for sure.. thanks
marc-andre menard