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

查看:17
本文介绍了如何列出 javascript 对象的函数/方法?(这甚至可能吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题的措辞是故意像这个问题.

This question is intentionally phrased like this question.

我什至不知道这是否可行,我记得依稀听到一些在 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天全站免登陆