SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: javascript variables
-
Jul 7, 2000, 12:57 #1
- 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
-
Jul 7, 2000, 14:01 #2
- 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!
-
Jul 10, 2000, 00:52 #3
- 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