[thelist] JS typeof operator limitations
Rory.Plaire at wahchang.com
Rory.Plaire at wahchang.com
Fri Nov 30 14:01:29 CST 2001
+| what sort of detailed information are you looking to get?
+| you may not be
+| aware that all objects in javascript can be interacted with
+| in the same way.
If an object is an Array.
Specifically, the document.forms array.
Interestingly if you pass document.forms into a function, and
document.forms[0] into the same function later, you get different results
than expected.
For instance:
function checkFormSet(formSet)
{
if(formSet.length > 0)
alert(formSet[formSet.length-1].name;
}
When you pass the array to the function above, you get the name of the last
form.
When you pass a form from the forms array, you get the name of the last
element.
If you try to check with the typeof operator, you get "object" both times.
8/
The only way around this is to check the type property... for forms, it is
undefined (i.e. == null in IE), for elements, it is the type of the element.
This seems a little kludgy, but since it works, I'm thinking of going for
it, unless there is something more elegant.
<rory disposition="Evolt: protects you from the irks of quirky browsers."
alt="8)"/>
More information about the thelist
mailing list