listing all functions in JavaScript

We are using JavaScript environment inside of another product.

I would like some code that would list all of the functions that are available ?

Its simple to interrogate an object for all of its methods and properties.
But how do we list all the possible top level objects/Methods/Properties that java and/or the vendor may have exposed ?

Thanks
sidwelleAsked:
Who is Participating?
 
RobConnect With a Mentor Owner (Aidellio)Commented:
@leakim - not sure there's a console to use here... RHINO is a javascript engine within a Java program

@sidwelle - did you use the RHINO Javascript debugger I posted previously?  I assume that showed you everything you need?
0
 
James BilousConnect With a Mentor Software EngineerCommented:
You can't do this with javascript itself, just look up a list of the Javascript API such as this one and hardcode it.
0
 
sidwelleAuthor Commented:
Thank you, but what I am looking for is a technique to display objects that the vendor has exposed that would not be documented in an open format like the one you suggested.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
RobOwner (Aidellio)Commented:
console.dir(variable)

run that in the dev tools of the browser and you'll see everything to do with the object
0
 
sidwelleAuthor Commented:
Thank you for that, but this is not a browser environment.  This is an implementation of RHINO w/in another product.  All I get is the opportunity to write scripts in a window.

When the script executes a statement and the interpreter looks up that command either in a object list of some type,  how to I iterate through that list and show all the top level objects ?

Thank you.
0
 
RobOwner (Aidellio)Commented:
okay, the console aside, to loop through the top level objects, methods etc you can use a simple for loop.  I've used "console.log()" here so you would need to replace that with however you output in RHINO:

for (d in document) {
    console.log(d+": "+typeof(document[d]));
}

outputs:
captureEvents: function
releaseEvents: function
implementation: object
URL: string
documentURI: string

Open in new window

0
 
sidwelleAuthor Commented:
That doesn't help because I don't have a document.  I am not evaluating a page.

I assume what the product does is take what little javaScript that I write and run it in an eval statement.

Thanks
0
 
RobOwner (Aidellio)Commented:
The use of "document" was for this example, substitute it for the object you want to enumerate
0
 
RobOwner (Aidellio)Commented:
In other words:

for (iterator in myobject) {
....
\\iterator will hold each property
}
0
 
sidwelleAuthor Commented:
I am not looking to iterate a specific object,  I want a list of all top level objects so that I can iterate through each one.

If there is a cmd in the environment names "doSomething()", how do I learn what the parent object is or other cmds that I don't have documentation to  ?
0
 
RobOwner (Aidellio)Commented:
http://mozilla.github.io/rhino/javadoc/index.html outlines the available objects that you can access from JavaScript.

As for the vendor object, if there's no documentation then the only thing you can do is iterate over the vendor object and filter for function types
0
 
RobOwner (Aidellio)Commented:
This is also a job for the debugger: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Debugger

It will allow you to graphically display the variables, objects and available functions
0
 
sidwelleAuthor Commented:
Still looking for some cmds that will expose the vendor types ?

If I know that, iteration would be great !
0
 
RobOwner (Aidellio)Commented:
Did you try the debugger?
0
 
leakim971PluritechnicianCommented:
The following work for jQuery which store function in the "fn" member object :
Test page : https://jsfiddle.net/0zour8fe/
for(var v in jQuery.fn) 
    if(typeof jQuery.fn[v]==="function") console.log(v);

Open in new window


or again :
for(var v in jQuery.fn) 
    if(typeof jQuery.fn[v]==="function") console.log(v + ": " + jQuery.fn[v]);

Open in new window

0
 
leakim971Connect With a Mentor PluritechnicianCommented:
using RHINO, for debugging purpose, you need to replace :
"console.log" by "print"
in my previous code
0
 
sidwelleAuthor Commented:
I am inside of another product, and that product supplies a text box for users to type small script-lets and then test them by hitting a test button.  No console or popups, smart syntax.  I do understand that the product is built on top of the Rhino engine, but thats all, and no other documentation is supplied.
By hunting around I have found that a nuber of objects do exist and are accessable and usable. Here are a few:
java.lang.string
java.io.File
java.io.FileReader
java.lang.system
0
 
leakim971PluritechnicianCommented:
look like java object... not javascript...
0
 
sidwelleAuthor Commented:
Its Java that I am calling form JavaScript.

Thank you for your posts, but I don't have a JScript object either.

I have had some success just working through the Rhino Java manual and testing to see what objects are available.

I posted another question about storing values in Java, maybe you could take a look at that question ?
(what is a "java.lang.System Property")

I am going to request this question be closed and give you guys the points.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.