将Math对象转换为实际对象

时间:2014-11-28 17:01:17

标签: javascript

有没有一种方法可以将Math对象转换为“真正的”javascript对象?

我想在Object.keys对象上使用Math。这可能不会一直硬编码吗?

1 个答案:

答案 0 :(得分:1)

Math的属性不可枚举,因此Object.keys(Math)返回一个空数组。

但是,您可以使用

Object.getOwnPropertyNames(Math)

它会产生类似

的东西
["toSource","abs","acos","asin","atan","atan2","ceil","clz32","cos","exp","floor","imul","fround","log","max","min","pow","random","round","sin","sqrt","tan","log10","log2","log1p","expm1","cosh","sinh","tanh","acosh","asinh","atanh","hypot","trunc","sign","cbrt","E","LOG2E","LOG10E","LN2","LN10","PI","SQRT2","SQRT1_2"]