Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

listing all functions in JavaScript

Posted on 2016-10-28
19
Medium Priority
?
291 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 500 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 

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 1000 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 500 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A solution for Fortify Path Manipulation.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

705 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