Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
propertyIsEnumerable & hasOwnProperty

hasOwnProperty

propertyIsEnumerable

哪些属性会在for... in ...中遍历, 哪些不会,可以通过propertyIsEnumerable进行测试

var a = ['is enumerable'];  
a.propertyIsEnumerable(0);          // returns true  
// 在javascript中array的也是通过hash map实现只不过index换成了number,所以0在这里也是enumerable的属性就可以理解了
a.propertyIsEnumerable('length');   // returns false  

Math.propertyIsEnumerable('random');   // returns false  
this.propertyIsEnumerable('Math');     // returns false  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.