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


Groups > comp.lang.javascript > #15872

Re: Simple array reference question

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!193.141.40.65.MISMATCH!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 <3865616.zCVvmSepPV@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Wed, 12 Sep 2012 15:36:52 +0200
User-Agent KNode/4.4.11
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: Simple array reference question
Newsgroups comp.lang.javascript
References <k2pn0l$n7v$1@news.albasani.net> <c0320514-716c-4955-8300-dae91763293f@googlegroups.com>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 37
NNTP-Posting-Date 12 Sep 2012 15:36:53 CEST
NNTP-Posting-Host bd94da5f.newsspool3.arcor-online.net
X-Trace DXC=TPEbh?9C4\LAa;:RKVJ>LEMcF=Q^Z^V3H4Fo<]lROoRA8kF<OcfhCOK9aNUc68?K]HDZm8W4\YJNLR=i2=[N6Y6JjC[Tb@]H]SJbATn64Lk_GI
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:15872

Followups directed to: comp.lang.javascript

Show key headers only | View raw


marat.rheingold@gmail.com wrote:

> Use named access like
> alert(window[param]);
> 
> Details: your arrays defined in scope of window. so you can access to them
> not only by variable name but as window property by their names

Wrong.  The correct answer is that variables are properties of the *Global* 
Object.  It can be referred to reliably by `this' in the global execution 
context:

  window.alert(this[param]);

Referring to variables as properties of the host object referred to by the 
host-defined `window' property of the Global Object is implementation-
dependent and unreliable, because that object may have properties with the 
same name (it certainly *has* host-defined properties) which can shadow 
user-defined variables.

It is of course a bad idea to rely on several global variables in the first 
place, and the substring() method is insufficient here.  A viable approach 
would include code like this:

  var params = (typeof Object.create == "function")
             ? Object.create(null)
             : {};

  params.all_ = (String(window.location.search).match(/^\??(.*)/)
                  || [, ])[1];

  … params.all_ …


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

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


Thread

Simple array reference question Tuxedo <tuxedo@mailinator.com> - 2012-09-12 12:09 +0200
  Re: Simple array reference question SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-09-12 12:37 +0200
    Re: Simple array reference question Tuxedo <tuxedo@mailinator.com> - 2012-09-12 13:08 +0200
      Re: Simple array reference question Stefan Weiss <krewecherl@gmail.com> - 2012-09-12 16:03 +0200
        Re: Simple array reference question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-12 16:42 +0200
  Re: Simple array reference question marat.rheingold@gmail.com - 2012-09-12 05:34 -0700
    Re: Simple array reference question Tuxedo <tuxedo@mailinator.com> - 2012-09-12 15:10 +0200
    Re: Simple array reference question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-12 15:36 +0200
      Re: Simple array reference question Tuxedo <tuxedo@mailinator.com> - 2012-09-12 20:59 +0200

csiph-web