Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > how to get the list of local variables

Reply
Thread Tools

how to get the list of local variables

 
 
schettino72
Guest
Posts: n/a
 
      08-23-2007
hi,

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

cheers,
Eduardo

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-23-2007
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>
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-23-2007
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)
 
Reply With Quote
 
schettino72
Guest
Posts: n/a
 
      08-23-2007
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){
....




 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-24-2007
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
 
Reply With Quote
 
schettino72
Guest
Posts: n/a
 
      08-24-2007
> 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

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-24-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can local function access local variables in main program? Sullivan WxPyQtKinter Python 10 11-08-2007 02:51 PM
different handling of local variables and instance variables when undefined Tammo Tjarks Ruby 2 09-13-2007 06:29 PM
local variables and global variables king Perl Misc 2 06-27-2006 03:13 PM
get list of member variables from list of class Oliver Eichler Python 1 01-28-2005 09:33 AM



Advertisments