Object.prototype.propertyIsEnumerable

Source: Internet
Author: User

Grammar:

Obj.propertyisenumerable (prop);

This method returns a Boolean value that indicates whether the specified property name is an enumerable property of the current object.

1. If the user has customized the properties of the object, it will return true, such as

var o == ' I am an enumerable attribute 'function() {}; // user-defined attribute Console.log (o.propertyisenumerable (' prop ')); // trueconsole.log (o.propertyisenumerable (' fn ')); // true

To iterate through the O object with for, the result is:

For (Var property in o) {    console.log;} PROP FN

2. If the engine has built-in object properties and inherited properties

var ob = {};
Console.log (ob.propertyisenumerable (' Keys ')); // false  keys--> from the object constructor Console.log (Ob.propertyisenumerable (' constructor ')); // false  constructor--> from Object prototype property

Iterate over the Ob object with for in, and the result is empty.

3. If a custom type is the case

function Dog (name) {    this. Name =function() {    varthis  . Name; var New Dog (' Huang '); Console.log (dog.propertyisenumerable (//true ' name ') and the constructor from the dog type Console.log (dog.propertyisenumerable (' sayname ')); // false ' Sayname ' and inherit from dog type

Using for in to traverse the dog object, the result is:

 for (var in dog) {    console.log;} // name Sayname

Sayname can traverse it, but he is not a property of the dog itself.

4. If you are dynamically adding the object method

var obj = {};  = ' green '; Console.log (obj.propertyisenumerable (' Color ')); //

Iterate over the Obj object with for in, and the result is empty.

In summary: If the property is not a property of its own, it inherits the property, returns False, or False if this property is not enumerable, that is, the property is built into the engine, and the rest returns True.

Object.prototype.propertyIsEnumerable

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.