how to get the list of local variables

Discussion in 'Javascript' started by schettino72, Aug 23, 2007.

  1. schettino72

    schettino72 Guest

    hi,

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

    cheers,
    Eduardo
     
    schettino72, Aug 23, 2007
    #1
    1. Advertising

  2. 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>
     
    Thomas 'PointedEars' Lahn, Aug 23, 2007
    #2
    1. Advertising

  3. schettino72

    Evertjan. Guest

    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)
     
    Evertjan., Aug 23, 2007
    #3
  4. schettino72

    schettino72 Guest

    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){
    ....
     
    schettino72, Aug 23, 2007
    #4
  5. 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
     
    Thomas 'PointedEars' Lahn, Aug 24, 2007
    #5
  6. schettino72

    schettino72 Guest

    > 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
     
    schettino72, Aug 24, 2007
    #6
  7. 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
     
    Thomas 'PointedEars' Lahn, Aug 24, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andres
    Replies:
    1
    Views:
    5,308
    dgoyani
    Oct 23, 2007
  2. Oliver Eichler
    Replies:
    1
    Views:
    426
    Peter Otten
    Jan 28, 2005
  3. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    684
    Antoon Pardon
    Nov 8, 2007
  4. Tammo Tjarks
    Replies:
    2
    Views:
    294
    Tammo Tjarks
    Sep 13, 2007
  5. king
    Replies:
    2
    Views:
    177
    Tad McClellan
    Jun 27, 2006
Loading...

Share This Page