This might seem like a really daft question, but I couldn''t find an answer anywhere. How do you add something to an enumerable object? Something like var first = $A(getElementsByTagName(''td'')); var second = $A(getElementsByTagName(''tr'')); first.PUSH(second); where the PUSH is something unknown. am i supposed to use inject here in some way? Andreas
I might be wrong here, but I always assumed the Enumerables object was a base class and not instantiated on its own. However the Array object has all the functionality of Enumerables. Thus, all the normal Array functions (http://www.w3schools.com/jsref/jsref_obj_array.asp ) and the Enumerables are possible on an Array. Thus, your assumption is correct. You can use push() pop() and shift() etc. -Andrew Martinez -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Andreas Wahlin Sent: Wednesday, June 28, 2006 9:27 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Add to enumerable This might seem like a really daft question, but I couldn''t find an answer anywhere. How do you add something to an enumerable object? Something like var first = $A(getElementsByTagName(''td'')); var second = $A(getElementsByTagName(''tr'')); first.PUSH(second); where the PUSH is something unknown. am i supposed to use inject here in some way? Andreas _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Are you trying to use document.getElementsByTagName? Then you''re missing the document.-part (or whatever node you want to use) this should work fine: var first = $A(document.getElementsByTagName("td")).push("..."); As for extending an enumarable object (in this case an array) Object.extend(Array.prototype, { PUSH: function(elm) { // code } }) Ciao Martin On 6/28/06, Andreas Wahlin <andreaswahlin-cgr7CL/LOSDk1uMJSBkQmQ@public.gmane.org> wrote:> This might seem like a really daft question, but I couldn''t find an > answer anywhere. How do you add something to an enumerable object? > > Something like > var first = $A(getElementsByTagName(''td'')); > var second = $A(getElementsByTagName(''tr'')); > first.PUSH(second); > > where the PUSH is something unknown. > > am i supposed to use inject here in some way? > > Andreas > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
I probably formulated myself badly, I wanted to be able to add stuff, to something that you can do each() with :) For instance, the lovely $$() push worked just as advertised, sorry I didn''t try it out myself sooner. *slightly ashamed* Andreas On Jun 28, 2006, at 16:48 , Martin Ström wrote:> Are you trying to use document.getElementsByTagName? Then you''re > missing the document.-part (or whatever node you want to use) > > this should work fine: > > var first = $A(document.getElementsByTagName("td")).push("..."); > > As for extending an enumarable object (in this case an array) > > Object.extend(Array.prototype, { > PUSH: function(elm) { > // code > } > }) > > Ciao > Martin > > > On 6/28/06, Andreas Wahlin <andreaswahlin-cgr7CL/LOSDk1uMJSBkQmQ@public.gmane.org> wrote: >> This might seem like a really daft question, but I couldn''t find an >> answer anywhere. How do you add something to an enumerable object? >> >> Something like >> var first = $A(getElementsByTagName(''td'')); >> var second = $A(getElementsByTagName(''tr'')); >> first.PUSH(second); >> >> where the PUSH is something unknown. >> >> am i supposed to use inject here in some way? >> >> Andreas >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs