views:

52

answers:

2

If i want to take all functions and variables declared in my program in firefox i just iterate 'window' object. For example if i have var a=function() {}; i can use a(); or window.a(); in firefox, but not in IE. I have function iterating window object and writing all function names declared in program like that:

for (smthng in window) {
    document.write(smthng);
}

works in FF, in IE there are some stuff but nothing i declare before. Any ideas?

+2  A: 

This is a well known JScript bug.

In IE, global variables aren't enumerable unless you explicitly define them as properties of the window object.

var a = function () {};     // It won't be enumerated in a `for...in` loop
window.b = function () {};  // It will be enumerated in a `for...in` loop

The above two ways are really similar, the only difference is that a is declared with the var statement, and this make it non-deletable, while b can be "deleted".

delete window.a; // false
delete window.b; // true
CMS