JRS: In article <cv*************@news.t-online.com>, dated Sat, 26 Feb
2005 14:55:45, seen in news:comp.lang.javascript, Thomas Mlynarczyk
<bl*************@hotmail.com> posted :
I want to pass a variable to a function and that function should display
both the value and the name of that variable. As for the value - no problem,
but the name?
The name is not passed.
So you have
function Tom(X, ...) {...}
and at the time of a call
Par = 3 ; Tom(Par, ...)
you want to display something like
Tom(Par=3, ...)
Replace the call to
Tom(Par, ...)
with
Cat('Tom', 'Par', ...)
which a good regexp-using editor should be able to do and undo.
A function Cat can now write Tom and its parameter names just as in the
code, and can use, I think, standard addressing techniques to write the
values and to perform the function call originally intended.
Or you can replace the call with
Evil("Tom(Par, ...)")
A function Evil can write the original call; parse to determine the
values of the parameters, and insert those in Par=3 fashion; and use
standard exec or otherwise to make the original call.
In each case, Tom should be assumed to maybe return something; so it
should itself be called as part of a return statement, or in a way that
displays and returns its result.
AFAICS, something like one or both of those should work at least for the
ordinary sort of function calls such as could be written in many
languages; but not necessarily for everything. ALL UNTESTED.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.