如何列出javascript对象的函数/方法? (它甚至可能吗?)
问题描述:
这个问题有意地像这个问题。
我甚至不知道这是否可行,我记得有些人听说过JS中不可枚举的一些属性。
I don't even know if this is possible, I remember vaguely hearing something about some properties not enumerable in JS.
无论如何,简而言之:我正在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.
答
我认为这就是你要找的东西:
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
}
}