检查对象的继承属性 [英] inspect inherited properties of an object
问题描述
如何检查继承到对象的对象的属性?我不能使用Object.keys
和Object.getOwnPropertyNames
!
Object.keys :此方法返回由给定对象定义的所有可枚举属性名称的数组(inherited properties are not considered)
Object.getOwnPropertyNames :类似于Object.keys(obj)
,但另外返回不可枚举属性的名称(again, inherited properties are not included)
.
how inspect the properties of an object where inherited to object?i can''t use of Object.keys
and Object.getOwnPropertyNames
!
Object.keys:This method returns an array of all enumerable property names defined by a given object (inherited properties are not considered)
Object.getOwnPropertyNames:similar to Object.keys(obj)
but additionally returns the names of non-enumerable properties (again, inherited properties are not included)
.
var f = new Object();
f.l = 8;
Object.prototype.s = 9;
Object.defineProperty(Object.prototype, "constvar", {
enumerable: false,
value: 88
});
var g1 = Object.keys(Object);
var gg1 = Object.getOwnPropertyNames(Object); //don't contain 'constvar' where is not enumerable but exist s property where is enumerable
推荐答案
您可以从类的基本类型中获取这些属性.要获取基本类型:SomeObject.GetType().BaseType
祝你好运!
You can get those properties from the base type of a class. To get the base type:SomeObject.GetType().BaseType
Good luck!
这篇关于检查对象的继承属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!