Instead of looping through the array associatively (treating it as an
object, thus getting all the "fields" and not just the
"items" within
the array), change your loops so they treat the array as an array (not
an associative array, or "Object")
Instead of, "for (var p in a)", use a counter (indexed loop)...
for (var i = 0; i < fields.length; i++)
{
if (!fields[i].validate())
isValid = false;
}
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Jason
Hummel
Sent: Tuesday, February 07, 2006 3:34 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] Objects and Properties
I''m working on a legacy product and introducing prototype to make my
life a little easier and I''m running into some problems with the
properties being added to some built in objects like Array.
The product has a form validator that''s used all over that adds fields
(and some of the fields properties) that need to be checked to an
array called fields (edited for simplicity):
/* ***************** */
fields = new Array();
fields[pFieldName] = new Field(pFieldName, name);
/* ***************** */
Later on when it''s validating this field it does something like this:
/* ***************** */
for(var currentField in fields) {
if(!fields[currentField].validate()) {
isValid = false;
}
}
/* ***************** */
The previous developer used a for in loop to go through all the fields
in his array and run the validate method on each one... The problem is
there is a ton of extra methods in the object because prototype adds
all that ennumerable goodness to new Array objects. I tried to go
through and delete everything after making the array:
fields = new Array();
for(var i in this.fields) {
delete this.fields[i];
}
which works in IE but not Firefox, plus it seems like it''s not very
elegant. To make matters worse, for the time being, not every page
that uses the validator will have prototype linked in. So, I can''t
make changes to the validator that will break everything if prototype
isn''t on the page.
Any ideas how I can get these scripts to play nice?
Thanks in advance,
Jason
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
The information transmitted in this electronic mail is intended only for the
person or entity to which it is addressed and may contain confidential,
proprietary, and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon,
this information by persons or entities other than the intended recipient
is prohibited. If you received this in error, please contact the sender and
delete the material from all computers.