Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15872
| Message-ID | <3865616.zCVvmSepPV@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-09-12 15:36 +0200 |
| 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 |
Followups directed to: comp.lang.javascript
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
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