473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Possible to introspect a function & parameters ?

Hi,

I know you can do stuff with introspection to gather up passed-in args
for a Javascript function and that you can list all defined functions
like:

function a(abc,xyz,zzz) {
print(arguments[0]); //etc
}

And

for (i in this) {
if (typeof(this[i])=='function') { print(i); }
}

But is there a way of:

Finding all defined functions and returning the parameter list - and
also the 'return' (if any) ?

I would like to iterate over all Javascript objects, and just generate
a 'stub' of each function which I can use to generate documentation
and 'proxy' functions etc ?

Thanks in advance,

John
(examples set up in 'Rhino' Shell, rather than browser, hence 'print'
rather than 'document.write...' etc).
Nov 4 '08 #1
3 3705
monojohnny wrote:
[...] is there a way of:

Finding all defined functions and returning the parameter list - and
also the 'return' (if any) ?
Interoperable, only by parsing the source code, I'm afraid.
I would like to iterate over all Javascript objects, and just generate
a 'stub' of each function which I can use to generate documentation
A similar wheel has been invented already. I have been working on another,
IMHO better, version of it for quite a while now. And no, it does not roll yet.
and 'proxy' functions etc ?
What's that?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Nov 4 '08 #2
Thanks for the reply...that's a shame (that you have to parse the
source) - I guess I expected too much after looking at what 'Ruby' can
do :)

BTW: the 'proxy functions' , I was going to keep this top-secret and
make millions from my new framework...but hey... ;-)
This is my idea (as far as I know its my idea, but I'm not so stupid
to think this hasn't been thought of before , but I couldn't find
anything out there [apart from maybe 'javascript on rails' - but
that's not available to the outside world...).

I haven't completely thought it through, but here's the sketch:

You will need: Tomcat, Rhino. A browser.

1. SERVER-SIDE: JS

function doSomething(a,b,c) {
....
}
function returnSomething(x,y,x) { ...return JSON; }
function blah(a,b,c,d,e,f,g) { return JSON... }

2. During an initialise-stage of somesort : load up this js
(_assuming_ just func/var defs or filtering everything out that is
not...) define all functions,vars in a Rhino "Context", iterate, spit
out a 'proxy' version of each function to a new .js file....

Where each 'proxy' function would share the same method sig. and
return (if any), but would be designed to run in a browser.
Each proxy-function would look something like:

function doSomething(a,b,c) {
url="http://host:port/servlet?
function=doSomething&a=arguments[0]&b=arguments[1]&c=arguments[2]...." //
Pseudo-code, obviously a loop in reality
callSyncAjax(url);
}

function callSyncAjax(url) {
//make xmlhttprequest request here
}

I'm not sure, would probably need a 'ret_doSomething()' function as
well (so function pairs for each server-side equivalent), I'm also
thinking it should be 'sync' call not the usual 'async' call...but
again not really thought through all the options here...

Single controller servlet , server-side - which (assumes - since we
have a 'contract' of somesort in that the proxy-script was generated
from the original js) decodes the 'REST-style' request and builds up
the call to JS function server-side, the return of which gets JSON'd
up and sent back to client.

The reasons I'm thinking of this:

1. I haven't yet learnt JQuery or such like - so I might be missing a
trick already - I dunno.
2. If this worked, I like the idea of having being able to code model-
stuff entirely back-end, but then call the functionality front-end -
AND I get to
write one set of functions that could be used either side.
3. I think combined with hibernate and some 'context-pooling' on the
back-end, it could be that start of decent mini-framework (for my uses
at least).
4. I think also that it would be nice to write 'swing' apps using this
method - with very little (no) changes - of course I would have to
redo the 'view' code here, but the model/controller stuff should stay
good....

So if you ever finish your code, post somewhere would you ! It still
might make this work. (although possibly not as 'dynamic' as what I
was originally hoping - not to take anything away from your project
you understand - just disappointed that JS doesn't allow the full
extent of reflection that I thought it might have!)

Cheers

John


On Nov 4, 9:17*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
monojohnny wrote:
[...] is there a way of:
Finding all defined functions and returning the parameter list - and
also the 'return' (if any) ?

Interoperable, only by parsing the source code, I'm afraid.
I would like to iterate over all Javascript objects, and just generate
a 'stub' of each function which I can use to generate documentation

A similar wheel has been invented already. *I have been working on another,
IMHO better, version of it for quite a while now. *And no, it does not roll yet.
and 'proxy' functions etc ?

What's that?

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
* -- Richard Cornford, cljs, <f806at$ail$1$8300d...@news.demon.co.uk>
Nov 4 '08 #3
I have thought better-of:

//[Generate 'proxy script']...During an initialise-stage of
somesort...//

Hell, if the mechanism was fast enough, just dynamically generate it
in a servlet, then a simple reload in browser should fetch the latest
script, could be quite
nice as well, allowing (in effect) simultaneous changes to the
'contract' and the back-end logic).

I am aware I'm co-opting jargon willy-nilly as I go along BTW :-)
('proxy function', 'contract' etc... ;-) )

Nov 4 '08 #4

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

Similar topics

16
by: Steven T. Hatton | last post by:
In the following code, the only way I can figure out to pass an array of const is by setting the template argument to const in the instanciation expression. It would be (or seem to me) better if I...
28
by: Michael B. | last post by:
I tend to use rather descriptive names for parameters, so the old style of declaration appeals to me, as I can keep a declaration within 80 chars: void * newKlElem...
4
by: Dietmar Kuehl | last post by:
Hi, after reading the documentation on C# generics from several sources, I'm still unclear whether it is possible to infer associated types from a type argument. For example, if I have an...
6
by: Rich | last post by:
Hello, I have to create a table in an Access mdb (remotely) on the fly. Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...) Then I have to insert data: Insert Into tbl1 Values(" &...
11
by: vbgunz | last post by:
Hello all, I am just learning Python and have come across something I feel might be a bug. Please enlightenment me... The following code presents a challenge. How in the world do you provide an...
51
by: Paul Gorodyansky | last post by:
Hi, Ran into the following problem while trying to have a code to attach a Virtual Keyboard to any user's form: User clicks a button and my JavaScript changes outerHTML of say <textarea -...
3
by: RoxxorzIt | last post by:
Alright, all I'm trying to do at the moment is display who posted a topic from a page entirely separate from PHPBB. The problem is, it seems no matter what I do, I just can't find a way to do so. ...
1
by: Davy | last post by:
Hi all, How to get the class name of an object from an introspect way? For example, Class cls:pass obj = cls() I want to get function(obj) = 'cls'
12
by: neovantage | last post by:
Hi, I am working on an image to process it with different ways/options given in the page. My page name is cart and it has an uploaded image having thumbnail view. When i click on that thumbnail...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.