有没有一种方法可以将Math
对象转换为“真正的”javascript对象?
我想在Object.keys
对象上使用Math
。这可能不会一直硬编码吗?
答案 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"]