For some reason for(var i in Math){console.log(i)} doesn’t show the expected tan, cos, atan2, E, PI in Javascript.
For some reason for(var i in Math){console.log(i)} doesn’t show the expected tan, cos, atan2,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
Mathis a built in object whose properties are flagged non-enumerable. Many built in objects have this behavior, which is why looping over an array withfor..inwill not give you problems untilArray.prototypeis extended with user functions, which are always enumerable by default.Until recently non-enumerable was an internal property not accessible by regular Javascript code. However EMCAScript 5 specifies the ability to set the enumerability and writeability (try changing the value of
Math.PI) of any object property through Object.defineProperty().It also provides Object.getOwnPropertyNames() as a way to get a list of all properties of an object regardless of their enumerability.
Far as I know the only browsers that currently support these functions are Chrome and Safari. Firefox should support it at version 4. IE9 I am not sure about, but Microsoft has stated they intend to support the EMCAScript 5 standard eventually.
I do not believe there is any way to emulate this functionality in Javascript interpreters without explicit support.