[thelist] JS typeof operator limitations

Rory.Plaire at wahchang.com Rory.Plaire at wahchang.com
Fri Nov 30 15:18:48 CST 2001


.jeff denoted:

+| ah, but an array *is* an object.

That would explain all this "object" business!

Ahh, the joys of a loosely-typed language...

+| if you call it like this you'll get back the number of forms in the
+| document:
+| 
+| checkFormSet(document.forms);
+| 
+| however, if you call it like this you'll get back the number 
+| of elements in
+| the first form:
+| 
+| checkFormSet(document.forms[0]);
+| 
+| that's because you're referring to two different level of 
+| objects in each
+| one.  the first is referring to the forms array.  the second 
+| is referring to
+| a specific form in that forms array.  therefore, the length 
+| property in your
+| function will be looking in different places.
+| 

I felt this is what it was... in VB, this is called the default property.

+| ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
+| > 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.
+| ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
+| 
+| do you get null or 'undefined' when checking the "type" 
+| property for a form?
+| i would think you'd get 'undefined' because there is no 
+| "type" property.

Actually, IE understands "undefined" as well as a materialist*. If you ask
it "hey, what is the value of that variable that hasn't been defined yet?"
It says: "It's undefined, hey." (must be running the canadian version [duck]
8)

Then I say, "well, my trusty browser, if this variable is undefined do such
and such." Replies it: "Hah! ERROR! You can't check if that variable is
undefined! I don't understand what you mean!"

Then, meekly, I state, "ok, could you do such and such when it is null?"
Says it, "Gladly!"

Go figure.

+| how you approach the problem will be determined by what 
+| you're trying to do
+| in the first place that's causing the problem.  *grin*  what 
+| are you trying
+| to do that's causing you to encounter this?


Overgeneralize, of course! 8D

I want to have a general form checking function which I can pass either one
form on the page, or all of them, depending on what is being sent to the
server, etc. The function should be intelligent enough to say, "hey, I have
to run through all the elements on each of these forms", or, "you know,
thank goodness that I have this one form to process all the elements on and
check them for validity."

<rory disposition="hey, what can I say, I like smart, flexible code because
I am lazy..." alt=";)"/>

* a materialist is one who believes in materialism, which is the theory that
everything that is real exists in a physical form... that is, the physical,
observable, definable universe is the only reality. Of course, it is simple
to prove the paradox here... how can something be undefined and defined as
definable at the same time?




More information about the thelist mailing list