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


Groups > comp.lang.javascript > #19643

Re: variable access

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <5148182.RP0mX05cp1@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Sun, 05 May 2013 19:47:11 +0200
User-Agent KNode/4.8.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: variable access
Newsgroups comp.lang.javascript
References <90af5a5a-ba92-4745-917c-a8ad3ff54704@googlegroups.com> <51863ea9$0$6640$9b4e6d93@newsspool2.arcor-online.net> <c56b3a60-c211-4bf5-8e67-fdf1789fb5e8@googlegroups.com>
MIME-Version 1.0
Lines 79
NNTP-Posting-Date 05 May 2013 19:47:12 CEST
NNTP-Posting-Host 5d4f39d6.newsspool2.arcor-online.net
X-Trace DXC=aKNPS8S5=j3L2C_`koXfC5A9EHlD;3Yc24Fo<]lROoR18kF<OcfhCO;5EF936Ae=F4DZm8W4\YJN<b@mF9jNikd57a5\<`>]gf>B4IF1Z46f78
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19643

Show key headers only | View raw


saurabh.khemka4@gmail.com wrote:

> 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";

This is _not_ a variable declaration.  A variable declaration starts with

  var

followed by the variable identifier, and an optional initialization part.  

You are attempting to add a property named “game” to an object, which, by 
contrast to a variable declaration, can fail even if syntactically correct.  

For example, if there is an element with name or ID “abc” in your document, 
and you are using IE/MSHTML, this assignment *will* fail because the global 
object or another object before it in the scope chain already has a non-
writable property of that name that refers to the corresponding object.
 
> Inside that javascript,

There is no javascript.  <http://PointedEars.de/es-matrix>

> a method is called which changes its value to xyz.

OK.

> Now, when I try to access that variable game in another javascript
> file(2.js),

Client-side script resources never stand alone.  There is always a runtime 
environment that uses them.  Usually the runtime environment is a Web 
browser, and separate files are used in HTML with the “script” element.  
Where *exactly* are your “script” elements?
 
> value abc is only returned.

Values are returned by functions.  Where is your function?

> Please suggest.

Please RTFM and STFW.  This is neither Programming 101 nor a guessing game.

> In the html page of 2.js,

That is “_HTML document_ that includes the script resource 2.js”.

> Both the javascript files are included. First
> 1.js and below that 2.js.

So, assuming the simple assignment in 1.js worked at all, you have to find 
out which code in 2.js changes the value defined in 1.js.  It is impossible 
to say without your posting the relevant code.  Use a debugger.

Please do not use the borken Google Groups for posting; use a newsreader.  
And please get a real name.

<http://jibbering.com/faq/#posting>
<http://PointedEars.de/faq#posting>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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