I agree.

We have some code that needs to perform functions if certain variables
exist. I am writing code that is using .each to test for the existence
of the variable (i.e. if the var is null or undefined don't run the
code).


On Feb 25, 9:26 pm, pbcomm <pbc...@gmail.com> wrote:
> I know the scenario would be uncommon and while I was working with
> someone's code, some event on the page calls a function and passes an
> array which then is used in this function like this:
>
> jQuery.each(arr, function() {
>
> });
>
> At some point the array coming in is not an array but is undefined
> which causes this error. This could be checked before using each, but
> though it might be a good idea to check within each.
>
> try this just for fun:
>
> var arr;
> jQuery.each(arr, function() {
>
> });
>
> On Feb 25, 8:25 pm, Steven Black <ste...@stevenblack.com> wrote:
>
> > Do you have a test case for this one?
>
> > I have a hard-time imagining the scenario you describe when jQuery is
> > invoked properly.
>
> > I'm guessing that, in this particular situation, the object of
> > discourse isn't actually a jWuery object.  In other words, try
>
> >   $(myVar).each(...)
> > instead of
> >    myvar.each(...)
>
> > I'm guessing <s>.
>
> > **--**  Steve
>
> > On Feb 25, 8:03 pm, pbcomm <pbc...@gmail.com> wrote:
>
> > > If the object passed into jQuery.each is null or undefined you get an
> > > error at object.length on the first line. Maybe there should be a
> > > check if (object == null) return object;? What do we think?

Reply via email to