Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list the functions/methods of a javascript object? (Is it even possible?)

This question is intentionally phrased like this question.

I don't even know if this is possible, I remember vaguely hearing something about some properties not enumerable in JS.

Anyway, to cut a long story short: I'm developing something on a js framework for which I have no documentation and no easy access to the code, and it would greatly help to know what I can do with my objects.

like image 320
BenoitParis Avatar asked Dec 04 '10 10:12

BenoitParis


2 Answers

If you include Underscore.js in your project, you can use _.functions(yourObject).

like image 128
Allan Tokuda Avatar answered Sep 30 '22 11:09

Allan Tokuda


I think this is what you are looking for:

var obj = { locaMethod: function() { alert("hello"); }, a: "b", c: 2 };
for(var p in obj)
{
    if(typeof obj[p] === "function") {
      // its a function if you get here
    }
}
like image 45
Mike Glenn Avatar answered Sep 30 '22 10:09

Mike Glenn