// 测试数据定义
let symbolKey = Symbol('symbolKey');
function Obj(){
this.ownKey = 1;
this[symbolKey] = 2;
}
Obj.prototype.prototypeKey = 3;
let o = new Obj();
Object.defineProperty(o, 'unenumerableKey', {
enumerable: false,
value: 4
})
-
in
Local attribute or inherited attribute'ownKey' in o; // true symbolKey in o; // true 'prototypeKey' in o; // true 'unenumerableKey' in o; // true 'undefinedKey' in o; // false 本地、原型链上都没有的属性 'ownKey ' in o; // false 错误的空格
-
Object.prototype.hasOwnProperty()
Local attributeso.hasOwnProperty('ownKey'); // true o.hasOwnProperty(symbolKey); // true o.hasOwnProperty('prototypeKey'); // false 非本地属性 o.hasOwnProperty('unenumerableKey');// true o.hasOwnProperty('undefinedKey'); // false 本地、原型链上都没有的属性 o.hasOwnProperty('ownKey '); // false 错误的空格
-
Object.prototype.propertyIsEnumerable()
Local attributes and enumerable attributeso.propertyIsEnumerable('ownKey'); // true o.propertyIsEnumerable(symbolKey); // true o.propertyIsEnumerable('prototypeKey'); // false 非本地属性 o.propertyIsEnumerable('unenumerableKey'); // false 不可枚举属性 o.propertyIsEnumerable('undefinedKey'); // false 本地、原型链上都没有的属性 o.propertyIsEnumerable('ownKey '); // false 错误的空格
Note: Object.prototype.propertyIsEnumerable()
it is determined true property is not necessarily be used for...in
or Obejct.keys(o)
enumeration (e.g.: Symbol local property do bond)