How to get list of all static members of some class in javascript

javascript, oop, static

Solution

How are you trying to inspect them?

Why can't you just use the same iterator to go through your actual class?

var key = "";
for (key in MyClass) { console.log(key); }

This isn't your every-day language. Practically everything in JS is an object, including functions/constructor functions.

As such, what seems like "public static" to you, here, is actually just a method of an object, which can be iterated through, like any other object.

Also: prototyping IS public static. If you prototype a property into your instances, then all instances have a reference to that exact same property, and modifications of that property will change the reference for everyone else.

Problem

I would like to get list of all static members of some class. For example: I would like to get all static members of `Object` (like `Object.create` if avalible and so on). How can I do that? Example: ``` 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 ``` So, if I got more static members, I would like to get at least names of them. In this example I would like to get `alertName` and `doSomething`. With public members you can do something like that: ``` for (i in ClassA.prototype) { alert(i); } ``` How about with static members?

Original source