20

Dec

Filed in Code, JavaScript |

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.

  • http://jwinter.org/log/ Joe Winter

    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.

blog comments powered by Disqus