Discussion:
traversing an array.
Arnar Birgisson
2008-10-24 14:28:45 UTC
Permalink
Hi Sander,
var o = document.getElementsByTagName('input');
every(o,function(e){addValidFunc(e);return true})
this functions as expected, but I figured there must be a more elegant
way off doing this. I'm feeling very dense that I could not figure it
out by myself. I guess I need to fight my mental block ;)
Since you are explicitly returning "true" for each element, there's no
need to use "every". You can use forEach instead:

var o = document.getElementsByTagName('input');
forEach(o, addValidFunc);

If you care for using the Selector library you can replace the first line with

var o = $$('input');

cheers,
Arnar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
SanderElias
2008-10-24 14:31:27 UTC
Permalink
Hi Arnar!

See, I knew there was an better alternative!
Tested and works like a charm. Gee, I think I need a good night off
sleep!

Thanks a lot!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
SanderElias
2008-10-24 14:17:59 UTC
Permalink
Hi All,

I was away from JS for quite a while. A new project has landed, and I
need to get back on track again.
Now I found myself dong this:

var o = document.getElementsByTagName('input');
every(o,function(e){addValidFunc(e);return true})

this functions as expected, but I figured there must be a more elegant
way off doing this. I'm feeling very dense that I could not figure it
out by myself. I guess I need to fight my mental block ;)

regards
Sander Elias
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MochiKit" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to mochikit+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...