Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there a way to list all javascript standard object method?

I mean I'm trying to get all the built in methods of String so I was thinking and I did tried doing this:

for( var method in String ){
     console.log( method );
}
//I also tried this:

for( var method in String.prototype ){
     console.log( method );
}

But no luck. Also if there is a way that solution should work for all ECMAScript standard classes/objects.

Edit: I want to point out that the solution should work in server side environment also like rhino or nodejs.

And as much as possible not using a third party API/framework.

share|improve this question
Possible duplicate: stackoverflow.com/a/152573/875127 – Cianan Sims Mar 29 at 3:45
@CiananSims I think maybe not since this is more on built in classes. The answer there will not work for this question. – Richeve Bebedor Mar 29 at 3:47
2  
I see. Does stackoverflow.com/q/2257993/875127 shed any light? Looks to be a surprisingly non-trivial question. – Cianan Sims Mar 29 at 3:53
@CiananSims I think that one shed a light actually. I look into his answer. And it works! Thanks! stackoverflow.com/questions/2257993/… – Richeve Bebedor Mar 29 at 4:04

3 Answers

up vote 1 down vote accepted

Won't dir give you what you need?

console.log(dir(method))

EDIT:

This would work (try John Resig's Blog for more info):

Object.getOwnPropertyNames(Object.prototype) gives :

["constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "__defineGetter__", "__lookupGetter__", "__defineSetter__", "__lookupSetter__"]

Object.getOwnPropertyNames(Object) gives :

["length", "name", "arguments", "caller", "prototype", "keys", "create", "defineProperty", "defineProperties", "freeze", "getPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyNames", "is", "isExtensible", "isFrozen", "isSealed", "preventExtensions", "seal"]
share|improve this answer
The method dir returns undefined. What I was thinking is like a function or some sort of procedure that will return an array of built in methods. – Richeve Bebedor Mar 29 at 3:50
please see the edits – loxxy Mar 29 at 4:01
I cannot accept my own answer so I will accept yours :D – Richeve Bebedor Mar 29 at 4:09

You should be able to get the list of methods by checking the type of properties as explained here

Also try getOwnPropertyNames

share|improve this answer
Yeah my example and the answer there is similar. I just have to add a condition for testing if it is a function or not but as far as I observed it will not work also. – Richeve Bebedor Mar 29 at 3:55
1  
ok trial2. Check getOwnPropertyNames – Brian Mar 29 at 4:00

I got the answer from this post How to display all methods in a JavaScript object?

Thanks to CiannanSims

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.