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)开发者_StackOverflow社区;
}
works in FF, in IE there are some stuff but nothing i declare before. Any ideas?
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
Here's a workaround: JavaScript: List global variables in IE
精彩评论