How to find hidden properties/methods in Javascript objects?

后端 未结 4 1103
难免孤独
难免孤独 2020-12-18 15:05

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:



        
4条回答
  •  隐瞒了意图╮
    2020-12-18 15:36

    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"]

提交回复
热议问题