Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

List built in JavaScript standard object methods

List built in JavaScript standard object methods

Problem

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 node.js.

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

Problem courtesy of: Richeve Bebedor

Solution

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"]
Solution courtesy of: loxxy

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

List built in JavaScript standard object methods

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×