Peter van der Zee wrote:
> Adrian Olaru wrote:
>
>> ((person2||{}).address||{}).zip || "no zip");
>
> If you want these kind of key lookup storage structures, why not create a
> function to do it for you? Something like...
>
> var Config = {bridge:{meta:{name:'peter',age:29}}};
> function get(key){
> var arr = key.split('.'); // ['bridge','meta','name']
> var result = Config;
> while (arr.length && (result = result[arr.shift()]))
> console.log(result);
> return result;};
>
> var name = get('bridge.meta.name'); // peter
> var age = get('bridge.meta.age'); // 29
> var occupation = get('bridge.meta.children'); // undefined
There was a long interesting discussion of such functions on cljs last
year.
<http://groups.google.com/group/comp.lang.javascript/browse_thread/
thread/909ddea61f431a1a/>
-- Scott
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]