并非所有对象属性都是可迭代的。您只能在 for..in 循环中获得可迭代的属性。
由于window(恰好是全局对象)的大多数属性都是用户定义的全局变量,因此它们是可枚举的。
在现代 JavaScript 引擎中,您可以使用 Object.getOwnPropertyNames(obj) 来获取所有属性,包括可枚举的和不可枚举的:
>>> 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"]
更多详情请见Is it possible to get the non-enumerable inherited property names of an object?。