开发者

[javascript]Where are all functions in IE?

开发者 https://www.devze.com 2022-12-31 23:51 出处:网络
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, b

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

0

精彩评论

暂无评论...
验证码 换一张
取 消