Quote:
Originally Posted by venegal
Is there a particular reason (except for its name) why getArrayName has to return a string and not the appropriate array itself?
|
getArrayName isn't a real function, I just represented it that way for simplicity. It's actually getting the variable name from the HTML itself.
I originally passed the variable name into the HTML like so:
Code:
element.innerHTML = "<input id='id1' onclick='doSomething(" + arrayName + ");' />";
which prints the array name into the HTML (which could be "myArray" or "myArray['sub']"). And now I am getting it back when the user activates that input.
Quote:
Originally Posted by Old Pedant
I'm just curious why anybody would *WANT* to use window[ ] for anything like this.... Why don't you want to use eval?
|
Because it's extremely useful, and there's no sense in wasting resources and security on eval() when Javascript was nice enough to put all of the variable names in an already existing array for me.
Quote:
Originally Posted by Old Pedant
Note to original poster:...
|
That was a typo,
Code:
// The specific sub-array I want is not known immediately, but will be e.g.
// 'myArray' or 'myArray[sub]'
should have read
Code:
// The specific sub-array I want is not known immediately, but will be e.g.
// "myArray" or "myArray['sub']"
I fixed it in in the OP.