PDA

View Full Version : Global array?


maximus06
02-10-2008, 07:27 AM
I won't waste your time and get right to it: I'm looking for a global array to store various integers in.

In IE and FF I always used this:
window[test] = 65;

This worked fine in FF and IE, but safari doesn't play ball.
I'm not sure if window[] is a special reserved array in those browsers, since I didn't even initialize it before using it, it just worked 'right out of the box'. Anyways, I tried going:

var window = new Array();

AND

var window = [];

but safari won't budge. Whenever I add values to the array, and try to do something with those values, safari says its not declared/undefined. What am I doing wrong?

Kor
02-10-2008, 09:12 AM
You confound the notation:

window[test] is not an array, it is the reference for a property's value of an object, the Global Object window.

See also JSON (http://json.org)

All the global variables and functions are properties of the window object. If you want to initialize dynamically a global array, you can do it like

window[test]=[];

rnd me
02-10-2008, 02:46 PM
in fact, its not even a link to window.test, its a link to window."what ever the variable test evaluated to as a string"

maximus06
02-10-2008, 06:38 PM
You confound the notation:

window[test] is not an array, it is the reference for a property's value of an object, the Global Object window.

See also JSON (http://json.org)

All the global variables and functions are properties of the window object. If you want to initialize dynamically a global array, you can do it like

window[test]=[];

Edit: nvm, I got it. Thanks!

Kor
02-11-2008, 04:12 PM
Well, if test is not a previously defined variable, it should be a string:

window['test']=[];
this is equivalent with the global
var test=[];
or
var test=new Array();