Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: Declaring the same global variable multiple times Date: Mon, 08 Jun 2015 17:03:23 +0200 Organization: solani.org Lines: 22 Message-ID: References: <7kn8natinqhrjpa3luqivrlcbrkb2mule3@4ax.com> <38a42$55753cb7$6def49d5$28976@nntpswitch.blueworldhosting.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1433775802 19111 eJwNxckBwDAIA7CVaDlsxgkQ9h+h1Ueu8UTDwsN8fXMumUch1aJIcuQWEipaGK7ixkjTTrx/HxS8ELw= (8 Jun 2015 15:03:22 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 8 Jun 2015 15:03:22 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 X-User-ID: eJwFwQkBwDAIA0BLYw1P5EAB/xJ6p8fErsPUoKuLnRRrRmHiB8s5OFr8mlJ6u1YS07E+zuwHJpIR3Q== In-Reply-To: Cancel-Lock: sha1:zMywHHT0TAS9oacBLnswra/Kztw= X-NNTP-Posting-Host: eJwNx8EBgDAIA8CZCiTAOFrI/iPo/Q7Ow5tBMCBoK7GvDONj+09dt6uabuchYSZGpwXVs/0BHHoQrQ== Xref: csiph.com comp.lang.javascript:28044 Stefan Ram wrote: > Cezary Tomczyk writes: >> Instead of that > > (that = a global) > >> you may create singleton which can store your data in a >> property and add method to get/set values. >> Example: >> var example = { >> sharedVariable: undefined, > > And »example« is what? Not a global? Basically, `example` is a global, but the namespace pattern helps to *reduce* the number of globals. To *avoid* globals, IIFEs or the module pattern might be more appropriate. -- Christoph M. Becker