Why does an array lose it's type when referenced from another window?
Posted on 2001-08-02
I have done some experimenting, and I have found out, that there's a strange problem with types in Internet Explorer 5.5 (possibly other versions as well).
Example scenario :
var a1 = new Array("a", "c", "b");
var b1 = a1;
var a2 = window1.a1;
When I create an array (a1) in window1 and put data in it, and then create a reference to it (b1), then I can sort the array no problem, using either the original array (a1.sort(mySortFunc)), or the reference var (b1.sort(mySortFunc)).
Now, if I create a reference to this array from another window/frame (window2), and try to use sort() on that reference (a2.sort(mySortFunc)), then I get a runtime error of the type "JScript object expected", meaning that it thinks the reference a2 is not an array anymore, but my own type.
The funny thing is, that I can use the no-argument sort() with no error - it just doesn't have any function.
But if I try to use my own sorting function on the a2 reference, I get the runtime error.
I have tested this VERY thoroughly, and I am absolutely certain that is exactly the fact that it looses it's type that's the problem. It's not a problem with my sorting function or the adressing of the other window, so I don't need suggestions in that direction.
My question is this simple :
Is there any way to get a reference to a1 in window2 that still has retained it's type, so I can use the sort(myfunc) method on the reference, without runtime errors, and with success. If not : Why? is it a bug or a security limitation?
If I am unclear, then feel free to ask me as much as needed.