Not all object properties are iterable. You'll only get iterable properties in a for..in
loop.
Since most properties of window
(which happens to be the global object) are user-defined global variables, they are enumerable.
In modern JavaScript engines you can use Object.getOwnPropertyNames(obj)
to get all properties, both enumerable and non-enumberable:
>>> Object.getOwnPropertyNames(Math)
["toSource", "abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "exp", "floor", "log", "max", "min", "pow", "random", "round", "sin", "sqrt", "tan", "E", "LOG2E", "LOG10E", "LN2", "LN10", "PI", "SQRT2", "SQRT1_2"]
See Is it possible to get the non-enumerable inherited property names of an object? for more details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…