> I mentioned it because I saw this jquery statement:
> var headLink = $this.find("a:first").attr("href");
> If the a-tag doesn't exsist it gives an undefined
> ["headLink: ", undefined]
jQuery or Moo or plain JS-- you'll find that native DOM methods, and
the DOM wrappers that frameworks implement, return null when elements
are not found.
This makes chaining from these methods difficult because they will
either return a very exciting object *or* something that will kill
your function().function().function() chain in its tracks.
So you have to be sensitive to these conditions in some way. Either
step through with intermediate variables (preferable) or do something
wacky but fun using the || operator as I suggested. But you really
should come to an understanding of why each option works if you're
going to understand JS.
*Note that in theory, a third way to deal with null.function()
condition is via SEH (try-catch blocks). The problem is that while
this kind of exception will be handled, the `message` text is
different from browser to browser, and there's no standard code, so
your code can't react intelligently to it. For example, Gecko will say
"TypeError: ... is null", while Presto will say "TypeError: cannot
convert to ... to object". Too freeform to be useful; may not be
properly classed as an exception anyway. But again, good to know what
does and doesn't work.
-- S.