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