hasOwnProperty vs propertyIsEnumerable

后端 未结 4 1121
执念已碎
执念已碎 2020-12-29 05:52

Can anyone enlighten me, what is the difference between hasOwnProperty and propertyIsEnumerable:

4条回答
  •  清歌不尽
    2020-12-29 06:23

    Simply stated:

    hasOwnProperty will return true if and only if the property is the property of the object and is not inherited. This one is simple.

    and

    propertyIsEnumerable will return true if and only if hasOwnProperty returns true and the property is enumerable. So propertyIsEnumerable is one "additional requirement" on top of the hasOwnProperty test, and the name propertyIsEnumerable would be more accurate if it is hasOwnPropertyAndIsEnumerable.

    demo: http://jsfiddle.net/aby3k/

提交回复
热议问题