Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19642

Re: variable access

From Stanimir Stamenkov <s7an10@netscape.net>
Newsgroups comp.lang.javascript
Subject Re: variable access
Date 2013-05-05 19:39 +0300
Organization A noiseless patient Spider
Message-ID <km61q3$75c$1@dont-email.me> (permalink)
References <90af5a5a-ba92-4745-917c-a8ad3ff54704@googlegroups.com> <51863ea9$0$6640$9b4e6d93@newsspool2.arcor-online.net> <c56b3a60-c211-4bf5-8e67-fdf1789fb5e8@googlegroups.com>

Show all headers | View raw


Sun, 5 May 2013 05:48:36 -0700 (PDT), /saurabh.khemka4@gmail.com/:
> On Sunday, 5 May 2013 04:12:41 UTC-7, Martin Honnen wrote:
>> saurabh.khemka4@gmail.com wrote:
>>
>>> I have a javascript file where I am assigning some value to a
>>> variable. How do I access the same variable in some other
>>> javascript file? Please suggest.
>>
>> Inside of HTML documents in a browser? Simply include the
>> files
>>
>> <script src="file1.js"></script>
>> <script src="file2.js"></script>
>>
>> Then file2.js can access global variables defined in file1.js.
>
> Suppose I have a variable declared in javascript file(1.js)
>
> game = "abc";
>
> Inside that javascript, a method is called which changes its
> value to xyz.
>
> Now, when I try to access that variable game in another
> javascript file(2.js),
>
> value abc is only returned. Please suggest.

Are you sure the method from the first file modifying the variable 
value is called (if at all) before you access it from code in the 
second file?  To verify, place a statement invoking the given method 
at the end of the first file, like:

var game = "abc";
...
function myMethod() {
   game = "xyz";
}
...
myMethod();

> In the html page of 2.js, Both the javascript files are included.
> First 1.js and below that 2.js.

-- 
Stanimir

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

variable access saurabh.khemka4@gmail.com - 2013-05-05 03:19 -0700
  Re: variable access Martin Honnen <mahotrash@yahoo.de> - 2013-05-05 13:12 +0200
    Re: variable access saurabh.khemka4@gmail.com - 2013-05-05 05:48 -0700
      Re: variable access saurabh.khemka4@gmail.com - 2013-05-05 07:44 -0700
        Re: variable access "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-05 17:30 +0200
      Re: variable access Stanimir Stamenkov <s7an10@netscape.net> - 2013-05-05 19:39 +0300
      Re: variable access Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-05 19:47 +0200
        Re: variable access Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-06 01:09 +0200

csiph-web