Solved

listing all functions in JavaScript

Posted on 2016-10-28
  • Programming
  • Java App Servers
  • JavaScript
  • Java EE
  • JSP
  • +1
19
199 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
  • 8
  • 7
  • 3
  • +1
19 Comments
 
LVL 8

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 42

Expert Comment

by:Rob Jurd, EE MVE
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

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

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now