Solved

listing all functions in JavaScript

Posted on 2016-10-28
19
253 Views
Last Modified: 2016-11-19
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
0
Comment
Question by:sidwelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 3
  • +1
19 Comments
 
LVL 9

Assisted Solution

by:James Bilous
James Bilous earned 125 total points
ID: 41864521
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
 

Author Comment

by:sidwelle
ID: 41864530
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
 
LVL 43

Expert Comment

by:Rob
ID: 41865118
console.dir(variable)

run that in the dev tools of the browser and you'll see everything to do with the object
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 

Author Comment

by:sidwelle
ID: 41865127
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
 
LVL 43

Expert Comment

by:Rob
ID: 41865555
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
 

Author Comment

by:sidwelle
ID: 41865816
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
 
LVL 43

Expert Comment

by:Rob
ID: 41866138
The use of "document" was for this example, substitute it for the object you want to enumerate
0
 
LVL 43

Expert Comment

by:Rob
ID: 41866143
In other words:

for (iterator in myobject) {
....
\\iterator will hold each property
}
0
 

Author Comment

by:sidwelle
ID: 41866262
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
 
LVL 43

Expert Comment

by:Rob
ID: 41866269
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
 
LVL 43

Expert Comment

by:Rob
ID: 41866270
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
 

Author Comment

by:sidwelle
ID: 41867639
Still looking for some cmds that will expose the vendor types ?

If I know that, iteration would be great !
0
 
LVL 43

Expert Comment

by:Rob
ID: 41867782
Did you try the debugger?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41875464
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
 
LVL 43

Accepted Solution

by:
Rob earned 250 total points
ID: 41883194
@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
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 125 total points
ID: 41883619
using RHINO, for debugging purpose, you need to replace :
"console.log" by "print"
in my previous code
0
 

Author Comment

by:sidwelle
ID: 41886927
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
 
LVL 82

Expert Comment

by:leakim971
ID: 41887127
look like java object... not javascript...
0
 

Author Closing Comment

by:sidwelle
ID: 41894293
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question