There is no cross browser method. In Internet Explorer, defined variables and functions become members of the window
object but are non enumerable. You can check for their existence using funcName in window
, but you can't enumerate them using a for...in
statement.
Variables that are defined as properties of the window object are enumerable:
function someFunc () {} // is not enumerable
window.someOtherFunc = function () {} // is enumerable
EDIT JScript's implementation is (surprise, surprise) actually wrong, as outlined in this blog post by Eric Lippert.
But I don't think you want to prefix all your variables with window.
, do you? For a method that will work in some browsers, see Josh Stodola's answer.