0

Is there a nice way to convert Math object into "real" javascript object?

I want to use Object.keys on Math object. Is that possible to not hardcode it all the way down?

Are
  • 2,160
  • 1
  • 21
  • 31
  • The properties of the Math object are not enumerable. What are you trying to achieve? – Pointy Nov 28 '14 at 17:02
  • I need to wrap every Math function in another function and I was wondering if I have to do this in the hard way. – Are Nov 28 '14 at 17:04
  • Its not "dupe" since I wanted to convert `Math` object. – Are Nov 28 '14 at 17:06

1 Answers1

2

The properties of Math are not enumerable, so Object.keys(Math) returns an empty array.

However, you can use

Object.getOwnPropertyNames(Math)

It will produce something like

["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"]
Oriol
  • 274,082
  • 63
  • 437
  • 513