属性检测 In,hasOwnPreperty()和propertyIsEnumerable()

IN  左侧是属性名;右侧是对象名, 如果 属性是 自有属性 或者继承属性 则返回 TRUE

var o={x:1,y:2}

"x" in  o    返回 true;

hasOwnProperty()   用来检测对象的属性 是否是 自有属性。

var  o={x:1};

o.hasOwnProperty("x")   返回 true

o.hasOwnProperty("tostring")  返回 false。

propertyIsEnumerable()   检测 是自有属性 且为枚举类型的时候 才返回 true。

原文地址:https://www.cnblogs.com/sunzhenyong/p/4045111.html