Is there a way to print all methods of an object? [duplicate]

Sure:

function getMethods(obj) {
  var result = [];
  for (var id in obj) {
    try {
      if (typeof(obj[id]) == "function") {
        result.push(id + ": " + obj[id].toString());
      }
    } catch (err) {
      result.push(id + ": inaccessible");
    }
  }
  return result;
}

Using it:

alert(getMethods(document).join("\n"));

Leave a Comment