20

Dec

Filed in Code, JavaScript with 1 comments |

I was working with some JavaScript code today (for our new moderation tools on Curse), and found something interesting. Let me first say by in no way do I claim to be a JavaScript expert, so don’t tease me too much.

JavaScript dir() method

function dir(object)
{
    methods = [];
    for (z in object) if (typeof(z) != 'number') methods.push(z);
    return methods.join(', ');
}

This works on certain elements and outputs a list like it would in Python, of all the methods that are attached to it. I added the typeof() clause to stop it from outputting slices.

Maybe there’s a better way to do this (without a debugger), but this was my best guess.

1 Responses to "dir() in JavaScript"

Subscribe to this topic with RSS or get the Trackback URL
Joe Winter (Jan 30th):

console.dir() in Firebug usually does the trick for me. If you’re doing any JavaScript without Firebug, go check it out. It’s an incredible timesaver.

Leave A Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)

Note: Comments moderation may be active so there is no need to resubmit your comment.