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> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. <51863ea9$0$6640$9b4e6d93@newsspool2.arcor-online.net> 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]gf>B4IF1Z46f78 X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:19643 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 >> >> >> >> >> 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. > 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. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.