SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres a nice simple one for you!
    I have a site with about 4 functions in. One of the functions has a variable, therefore this is a local one. I need this variable to be accessible to the other functions, and i dont think i can pass it to these functions as arguments? - i solved (i think) my problem by creating global variables and not using var for the locals, which changes the value of the globals to what i want. - is this a reliable method? - is there a better way?

    Splendid bob

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are other ways, but you've hit upon the simplest and probably best way to do it: with global variables. Passing parameters would be ideal, but since you can't do this global variables are the way to go.



    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    As long as you do not use the global variable's name in another function, you are safe. As a general programming practice, globals are bad news -- especially if the code/script is located near code written by someone else (like cut&paste scripts).
    Out of curiousity, why can't you pass the var as an argument?

    Vinny



    ------------------
    my site:GrassBlade: cut&paste javascript
    moderator at:The JavaScript Place Forums
    Javascript City


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •