[Javascript] Subscript Notation

Terry Riegel riegel at clearimageonline.com
Fri Nov 11 08:46:38 CST 2011


Mike,

Your answer caused me to immediately say yeah but what if I don't know the scope of the object. But I do  know the scope of the object it is whatever scope the interpreter is currently running in isn't it?

So the answer to my question would appear to be...


this['a']

I ran this as a test...

eval('a')['name']===this['a']['name']

and as expected I get true.

The solution gives me an interesting perspective on what 'this' is and what it means. Many aspects of Javascript still seem like voodoo to me. Answers to questions like this help me solidify my understanding of the basics of javascript.

Thanks for your help.

Terry


On Nov 11, 2011, at 9:13 AM, Mike Dougherty wrote:

> On Fri, Nov 11, 2011 at 7:57 AM, Terry Riegel
> <riegel at clearimageonline.com> wrote:
>> So my question. Is it possible to use subscript notation for the first part of an object something like...
>> 
>> ['a'].name or ['a']name
> 
> if you have declared those objects in the scope of the window object,
> you could do something like this:
> var myobject = { name: 'terry' };
> var whatobject = 'myobject';
> var whatproperty = 'name';
> 
> alert( window[whatobject][whatproperty] );
> 
> if you're using a namespace object, replace "window" with your namespace.
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript

Terry Riegel

Put Your TimeClock on the Web
http://www.punchedin.com



More information about the Javascript mailing list