我想获取某个类的所有静态成员列表。例如:我想获取Object
的所有静态成员(如Object.create
等)。我该如何做到这一点?
示例:
var ClassA = function(){}
ClassA.prototype.getName = function(){return "ClassA";} //public method
ClassA.alertName = function(){ alert("ClassA");} //static method
ClassA.doSomething = function(){return "Do something";} //another static method
因此,如果我有更多静态成员,我希望至少能获取它们的名称。在本例中,我想要获取 alertName
和 doSomething
。对于公共成员,您可以这样做:
for (i in ClassA.prototype) {
alert(i);
}
静态成员怎么样?