qqryq
qqryq

Reputation: 1924

[javascript]Where are all functions in IE?

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?

Upvotes: 1

Views: 153

Answers (2)

Ron
Ron

Reputation: 8156

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

Upvotes: 0

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827316

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

Upvotes: 2

Related Questions