Justin Palmer
2005-Dec-09 09:48 UTC
[ANN] Prototype Enumerable, Array and Hash Documentation
Hey guys, I recently published an article documenting some of the more useful and interesting parts of Prototype''s Enumerable, Hash and Array objects. You can find it here: encytemedia.com/blog/articles 2005/12/07/prototype-meets-ruby-a-look-at-enumerable-array-and-hash If you have any feedback or suggestions, fire away. Cheers, -Justin Palmer ---------------------------------------------- Encytemedia.com Professional User Interface Design for Rails Applications
Maninder, Singh
2005-Dec-15 11:17 UTC
RE: [ANN] Prototype Enumerable, Array and Hash Documentation
Hi Justin, Thomas, Thanks for the documentation. I have one question though - how do I extract the value of any particular key directly? For eg: Suppose I have a hash - var h = $H({name: "john doe", email: "john-Ch9RrZxMC0c@public.gmane.org", msg: "say hello to me"}); h.keys(); //gives me name/email/msg h.values() //gives me john doe/john-Ch9RrZxMC0c@public.gmane.org/say hello... What if I want to know the value of name or email or msg? Does it have something like - h.value(name) or something? I want to be able to get the value using the key without writing any loops. Any help would be appreciated. Thank you, Mandy.
Nicolas Terray
2005-Dec-15 11:57 UTC
Re: [ANN] Prototype Enumerable, Array and Hash Documentation
On 12/15/05, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> Suppose I have a hash - > var h = $H({name: "john doe", email: "john-Ch9RrZxMC0c@public.gmane.org", msg: "say hello to me"}); > > h.keys(); //gives me name/email/msg > h.values() //gives me john doe/john-Ch9RrZxMC0c@public.gmane.org/say hello... > > What if I want to know the value of name or email or msg? > > Does it have something like - > > h.value(name) or something? I want to be able to get the value using the key without writing any loops. >h[''name''] ?
Maninder, Singh
2005-Dec-15 12:01 UTC
RE: [ANN] Prototype Enumerable, Array and Hash Documentation
That works Nicolos! Thanks. But, I was wondering that such support is already built in javascript. Why did we have to wrap it in $H for this? Thanks, Mandy.
Maninder, Singh
2005-Dec-15 12:02 UTC
RE: [ANN] Prototype Enumerable, Array and Hash Documentation
And so does - h.name h.email h.msg :) -----Original Message----- From: Maninder, Singh Sent: Thursday, December 15, 2005 5:31 PM To: ''rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org'' Subject: RE: [Rails-spinoffs] [ANN] Prototype Enumerable,Array and Hash Documentation That works Nicolos! Thanks. But, I was wondering that such support is already built in javascript. Why did we have to wrap it in $H for this? Thanks, Mandy.
Nicolas Terray
2005-Dec-15 12:27 UTC
Re: [ANN] Prototype Enumerable, Array and Hash Documentation
On 12/15/05, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> That works Nicolos! Thanks. > > But, I was wondering that such support is already built in javascript. > > Why did we have to wrap it in $H for this? >I use $H() only when I want to iterate over keys or value. Example var options = {} options[''v1''] = new Option(''v1'', ''v1''); options[''v2''] = new Option(''v2'', ''v2''); options[''v3''] = new Option(''v3'', ''v3''); $H(options).keys().each(function(key) { doSomethingWith(key); }); As I am new to prototype, I have not usefull examples... And maybe my example can be accomplished in a more beautifull way.