propertyIsEnumerable

The “propertyIsEnumerable” function always excludes properties that would not return true for “hasOwnProperty”. You’ve done nothing to make any properties not be enumerable, so in your test the results are the same.

You can use “defineProperty” to define properties that are not enumerable; see this reference at MDN.

Object.defineProperty(obj, “hideMe”, { value: null, enumerable: false });
That’s like:

obj.hideMe = null;
except the property won’t show up in for … in loops, and tests with propertyIsEnumerable will return false.

This whole topic is about features not available in old browsers, if that’s not obvious.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: