1

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?

qqryq
  • 1,684
  • 3
  • 17
  • 19

2 Answers2

2

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
Christian C. Salvadó
  • 769,263
  • 179
  • 909
  • 832
0

Here's a workaround: JavaScript: List global variables in IE

Community
  • 1
  • 1
Ron
  • 6,768
  • 11
  • 37
  • 40