473,799 Members | 3,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Browsing javascript functions and params

How to build or find an object browser for javascript?

E.g. Delphi integrated developement environment ('ide') offers a very
practical object browser for Pascal language. When typing a name with a
dot you get a list of objects,propert ies and methods to select from.
When you select or type a methodname or function and the left
parenthesis , the system writes the possible argument types. With key
F1 one gets thorough description of the object, property, method.

In javascript it is easy to get a list of object properties and its
contained objects t e.g. with this code:

function listObjectProp( obj){
var s='';
o=eval(obj);
for (var x in o){ s=s+typeof o[x]+":"+x+":"+o[x]+"\n";}
return s;
}

alert(listObjec tProp('window.d ocument.locatio n')); // any object name
possible as an argument

We get numbers, strings, booleans, objects and some user defined
functions to this list, but not all functions of objects.

How to get functions also? And their parameter lists? Is the only way to
make manually list of all those and fetch from that list with a script?

Venkman and Dom browser in Mozilla might be a way to go but they look a
bit heavy, when here a major part of the work might be done on those 6
code lines above :).

If using mailing address, remove XXXX
Jul 20 '05 #1
1 1610
optimistx <op***********@ hotmail.com> writes:
In javascript it is easy to get a list of object properties and its
contained objects t e.g. with this code:

function listObjectProp( obj){
var s='';
o=eval(obj);
you should make o a local variable, i.e.,
var o = ...
and you shouldn't use eval. So, drop o.
for (var x in o){ s=s+typeof o[x]+":"+x+":"+o[x]+"\n";}
return s;
}

alert(listObjec tProp('window.d ocument.locatio n')); // any object name
possible as an argument
Drop the eval and just pass the object. I.e.,
listObjectProp( window.document .location)
We get numbers, strings, booleans, objects and some user defined
functions to this list, but not all functions of objects.
That depends on the browser. E.g., Mozilla enumerates most properties,
Opera almost none. The ones that are not enumerated are mostly functions,
but doesn't hgave to be.

Each property of an object is either enumerated or not. The properties
you assign are always enumerable, but the ones provided by the system
might or might not be. Different browsers pick different choices where
it isn't specified. Some properties are always non-enumerable, like
the methods of Array.prototype (required to be non-enumerable by the
ECMAScript standard)
How to get functions also?
There is no way, short of guessing their names, if they are not
enumerable.
And their parameter lists?
There is no way that is *guaranteed* to work. You can get the number of
arguments. It is the length property of the function object.
You can try turning the function into a string and parse it as a function
declaration to get the names of the function arguments, but it is not
required to work. ECMA 262 says about Function.protot ype.toString:
---
An implementation-dependent representation of the function is
returned. This representation has the syntax of a
FunctionDeclara tion. Note in particular that the use and placement of
white space, line terminators, and semicolons within the
representation string is implementation-dependent.
---
It doesn't say that it has to preserve the names of the variables, although
it would be silly not to.

An example function that gets information out of a function:
---
function parseFunc(func) {
var str = func.toString() ;
// remove comments to EOL
str = str.replace(/\/\/.*\n/g,"\n");
// remove inline comments
str = str.replace(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,"");

var arity = func.length;
var match = /function\s*([a-zA-Z_$][\w$]*)?\s*\(([^)]*)\)/.exec(str);
var vars = match[2].split(/\s*,\s*/);
return {name:match[1],arity:arity,ar gs:vars};
}
---
The returned object has the proprties "name" (name of function, if any),
"arity", and "args".

The "name" can be undefined, because current browsers doesn't adhere
to the ECMA 262 standard. They can return a string without a name
for the function, which is then not a function declaration.
Is the only way
to make manually list of all those and fetch from that list with a
script?


For the standard properties which are not enumerated, yes. There is no
other way to find them than to check for them specifically.

For non-standard properties which are not enumerated, there is no way
except shooting in the dark.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2832
by: tekenenSPAM | last post by:
I know that one cannot cast a non-static member function to a void *. (http://users.utu.fi/sisasa/oasis/cppfaq/pointers-to-members.html) However, I have a case where I need to call a certain member function based on a value passed into another function. Since there are a large number of these values and therefore a large number of potential functions I need to call, I wanted to avoid using a massive switch statement (or equivalently,...
1
1846
by: SPG | last post by:
Hi, We have an applet that has to support the SUN VMs as well as the MS VM. The applet receives updates from a server (via tcp or http) and wraps them up as objects and passes them using the JSObject scripting context to a javascript function. This function takes the object and reads the properties and updates a screen.
1
6793
by: qwerty | last post by:
My end goal is to have a script that takes user input from one pageA, submits to pageB which then displays the parameter values entered on PageA. My problem is that the values are being displayed with any included spaces being replaced with the plus sign. Any help would be appreciated. pageA code: <html> <body> <form type="get" action="pageB.html" target="new"...
2
2364
by: ShinKaiser | last post by:
Hi there, I use a Javascript lightbox application known as lightwindow on my site, basically I have set up lightwindow to launch from flash via the javascript functions, light window launches in the same way as if it had been called from the HTML page. within the flash file I have this function: javascript: myLightWindow.activateWindow({rel: 'Dele', class: 'lightwindow page-options', href: 'gallery/11_image.jpg', title: 'Waiting for the...
1
2733
by: critchey1 | last post by:
Hey everyone, i've been playing around with trying to get some scripts to work with detecting whether flash player is installed on your computer or not. I found a flash detection kit on the adobe site which had a client side detection method using javascript. Basically what im trying to get it to do is if flash player is installed, use the style property display="none" to hide my static content, and if flash is not installed hide the flash...
9
3992
by: Gabriel Rossetti | last post by:
Hello, I can't get getattr() to return nested functions, I tried this : .... def titi(): .... pass .... f = getattr(toto, "titi") .... print str(f) .... Traceback (most recent call last):
0
1203
by: Gabriel Genellina | last post by:
En Wed, 20 Aug 2008 05:34:38 -0300, Gabriel Rossetti <gabriel.rossetti@arimaz.comescribi�: Yes, functions are objects, but inner functions aren't attributes of the outer; they live in its local namespace instead (and inner functions won't exist until the outer function executes) Try using locals()
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.