0

I have a page that renders just fine. On the page is a control and I wanted to set the visibility to hidden. I can get a handle on the object just fine but then when I went to use what I thought were pretty typical methods such as:

.setVisible(false);

or

.css("visibility", "hidden");

I got the object doesn't support method error.

Now to solve my visibility problem there was a containing div for the control so I just set the div to hidden.

$('#footer_statecode').hide();

My question however for the future is how would I discover the methods supported by an object.

My google searches came close such as this SO post but in these example the person had a specific method they were looking for. I am interested in seeing everything available....and it doesn't have to be via an alert(); I'd be just fine using some capability in the different browsers Developer tools (F12).

Thank you once again for sharing your knowledge.

7
  • possible duplicate of How to list the properties of a JavaScript object Commented Mar 7, 2014 at 13:32
  • 1
    In Firefox just type $('#footer_statecode'). in the console and a list of methods will appear. Im not sure about Chrome. Commented Mar 7, 2014 at 13:32
  • var support = "method" in obj; Commented Mar 7, 2014 at 13:32
  • @Andy Interestingly...for me in IE & Chrome $('#footer_statecode') in the F12 console resulted in full blown object exploration while firefox only gave me []?? Anyway it worked as you say. Thank You! Commented Mar 7, 2014 at 13:41
  • @A.Wolff am I missing something in your comment? Wouldn't that be a nice concise way to find a method IF you knew what to look for?...which I don't. Commented Mar 7, 2014 at 13:43

2 Answers 2

3

You can use this. It won't include built-in JavaScript methods (ex Array.prototype.push)

var methods = [];
for (var prop in object) {
  if (typeof object[prop] === "function") {
    methods.push(prop);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not checking on purpose
0

You can find it like this:

function getMethods(prop)
{ 
    var res = [];
    for(var prop in x) {
        if(typeof x[prop] == 'function') {
            res.push(prop);
        }
      }
        return res;
    }

You can also look at the Object.prototype.hasOwnProperty()

1 Comment

You are setting res to an empty array on each iteration. You are also returning inside the loop -- this will retrieve only one method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.