-1

I want to print out my functions and classes which are created by me on specific source file.

For example if we assume that;

my function's name is print()

print_func(script.js) this must print out functions in script.js

print_class(xyz.js) this must print out classes in xyz.js

Is there a way for this?

hakki
  • 6,181
  • 6
  • 62
  • 106

2 Answers2

0

You have to check all the properties of window object, and then check all the properties again after running the script.

This is for example how you get all the functions that exists before you run the script:

before=[];for (a in window) {if (typeof(window[a])=='function') before.push(a)   }
Shluch
  • 423
  • 4
  • 13
0

Nope, but if you assign the functions to an object, you can print out all it's available functions. Proper namespacing will help you achieve this easily.

See Is there a way to print all methods of an object in javascript?

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"));
Community
  • 1
  • 1
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260