I want to create an object with a non-enumerable property(a property that does not show up in a for (var x in obj loop). Is it possible to do this?
I want to create an object with a non-enumerable property(a property that does not
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.
It isn’t possible in ECMAScript 3 (which was what the major browsers implemented at the time this question was asked in 2010). However, in ECMAScript 5, which current versions of all major browsers implement, it is possible to set a property as non-enumerable:
This works in current browsers: see http://kangax.github.com/es5-compat-table/ for details of compatibility in older browsers.
Note that the property must also be set writable in the call to
Object.definePropertyto allow normal assignments (it’sfalseby default).