I would like to automatically determine all of the properties (including the hidden ones) in a given Javascript object, via a generalization of this function:
Object.getOwnPropertyNames
won't return "the hidden ones".
Object.getOwnPropertyNames
returns the names of non-inherited properties.
this works in firebug to find object methods.
Object.getOwnPropertyNames(Math);
ECMAScript 5th ed. defines Object.getOwnPropertyNames
that returns an array of all properties of the passed in object, including the ones that are non-enumerable. Only Chrome has implemented this so far.
Object.getOwnPropertyNames({a: 10, b: 2});
gives ["b", "a"]
(in no particular order)
Object.getOwnPropertyNames(Math);
gives ["LN10", "PI", "E", "LOG10E", "SQRT2", "LOG2E", "SQRT1_2", "LN2", "cos", "pow", "log", "tan", "sqrt", "ceil", "asin", "abs", "max", "exp", "atan2", "random", "round", "floor", "acos", "atan", "min", "sin"]
This is explained in a previous answer. Basically, the spec explicitly requires (using DontEnum
) that these objects aren't enumerable.