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

后端 未结 4 1408
梦谈多话
梦谈多话 2020-12-16 18:54

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 en

4条回答
  •  天涯浪人
    2020-12-16 19:24

    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
        }
    }
    

提交回复
热议问题