Losing reference to constructor when passing an array between windows.

C

Carlos Aguayo

If I have a parent and a child window, and if I create an array in the
child window, and pass it as a parameter to the parent window, it's
still an array, and its methods still work (like the 'forEach').

However, if I try to figure out if it's an array by looking at the
constructor property, I get that it's not an array. I got this behavior
in IE6 and Firefox, is this a bug or am I doing something wrong? I
pasted the code below.
Thanks!
Carlos

parent.html
======================================================
<html><body><script type="text/javascript">
var childWindow = window.open("child.html", "childWindow");
function functionInParentWindow(anArray){
if (anArray.constructor == Array){
alert("expected behavior");
} else {
alert("bug?");
}
}
</script></body></html>
======================================================

child.html
======================================================
<html><body><script type="text/javascript">
var parentWindow = window.opener;
var anArray = [];
anArray.push('0');
parentWindow.functionInParentWindow(anArray);
</script></body></html>
======================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top