473,385 Members | 1,676 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,385 software developers and data experts.

how to get the list of local variables

hi,

how can i get a list of all local variables defined in a function?

cheers,
Eduardo

Aug 23 '07 #1
6 4737
schettino72 wrote:
how can i get a list of all local variables defined in a function?
There is no access to the local Variable Object. So you would have to rely
on parsing the string representation of the Function object, which is left
as an exercise to the reader.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 23 '07 #2
schettino72 wrote on 23 aug 2007 in comp.lang.javascript:
how can i get a list of all local variables defined in a function?
You cannot, I think, not with js that is.

Why would you need that for?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 23 '07 #3
Thanks for the replies guys.
>
Why would you need that for?
I writing a unit test framework for javascript. Test cases are
defined by extending my TestCase base class. I want to automatically
find all defined test cases, so I need to introspect the code
somehow.
I solved my problem putting the test cases out of my "function" and
doing

for (var o in top){
....


Aug 23 '07 #4
schettino72 wrote:
>Why would you need that for?

I writing a unit test framework for javascript. Test cases are
defined by extending my TestCase base class.
Chance is that there is no class.
I want to automatically find all defined test cases, so I need
to introspect the code somehow.
I solved my problem putting the test cases out of my "function" and
doing

for (var o in top){
....
Given that the `in' operator is not supported before JavaScript 1.4,
JScript 5.0, ECMAScript 3, and that `top' is a host-defined property of
the Global Object, are you sure the results your test framework yields
are always correct?
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 24 '07 #5
Given that the `in' operator is not supported before JavaScript 1.4,
JScript 5.0, ECMAScript 3,
I am not worried about this...
and that `top' is a host-defined property of
the Global Object,
this was quick and dirty. i will probably load them in my own object/
namespace
are you sure the results your test framework yields
are always correct?
it worked fine with what i have in hand. but "always" is a too strong
word ;)

thanks for your comments.
eduardo

Aug 24 '07 #6
schettino72 wrote:
>and that `top' is a host-defined property of the Global Object,
this was quick and dirty. i will probably load them in my own object/
namespace
You can use `this' for referring to the global execution context in the
local execution context. You can then assign `this' to a global variable
and then use that variable locally.

var _global = this;

function ...()
{
... _global ...
}

However, using a user-defined object instead is a Good Idea[tm].

Please always provide attribution of quoted material.
Regards,

PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm
Aug 24 '07 #7

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

Similar topics

26
by: Alex Panayotopoulos | last post by:
Hello all, Maybe I'm being foolish, but I just don't understand why the following code behaves as it does: - = - = - = - class listHolder: def __init__( self, myList= ): self.myList =...
46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
3
by: ken.boss | last post by:
I am a python newbie, and am grappling with a fundamental concept. I want to modify a bunch of variables in place. Consider the following: >>> a = 'one' >>> b = 'two' >>> c = 'three' >>>...
0
by: Keith Davies | last post by:
Hi All, In my web page generation, I want to be able to automatically split (create a new page) on nodes that meet certain criteria. One is if the 'out:split' attribute is set to 'yes' (dead...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
7
by: Jorgen Bodde | last post by:
Hi, I am trying to simplify my code, and want to automate the assigning of variables I get back from a set. I was thinking of putting the variables I want changed in a list: L = ...
4
by: beginner | last post by:
Hi All, If I have a list comprehension: ab= c = "ABC" print c
8
by: Samant.Trupti | last post by:
Hi All, I am facing a strange problem.. I am calling a function func2 from func1. Before calling func2 all the local variables in func1 looks fine and has their respective values. When...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.