如何列出javascript对象的函数/方法? (它甚至可能吗?) [英] How to list the functions/methods of a javascript object? (Is it even possible?)

查看:137
本文介绍了如何列出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
    }
}

这篇关于如何列出javascript对象的函数/方法? (它甚至可能吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆