user3502374 user3502374 - 1 year ago 128
Javascript Question

Not understanding javascript window.frames.Array

Looking at below piece of code

var _Array = window.frames[window.frames.length-1].Array;

I truly don't understand what this means. I understand what Array is in javascript.. But what is this code doing? I get the window.frames[] part. What does adding .Array at the end do??

Please let me know. thank you.

Answer Source

Something like this might become more-clear if we break it down a bit.

// Get the global window object for the last frame on the page.
var iframeWindow = window.frames[window.frames.length-1];

// Get the Array constructor for the iframe window.    
var _Array = iframeWindow.Array;

window.frames is an array-like object, which contains all the frames in the window. Once you have a reference to one of them, you can access the frames global variables as properties of that object, just like you can access the globals for the current window through the window object. In this case, the frames global Array constructor is being accessed.

The equivalent code for getting the Array constructor for the current window would be:

var _Array = window.Array;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download