#11278 closed enhancement (invalid)
$.each: no usable message/notice/exception for undefined first argument
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | core | Version: | 1.7.1 |
Keywords: | needsreview | Cc: | |
Blocked by: | Blocking: |
Description
i'm using $.each to iterate through array, got from ajax. if this array variable is undefined, the whole script stops (with error in line 630 of jquery.js 1.7.1)
i spent a lot of time trying to find out the reason. of course, i'll add check for "undefined" of my variables. but i think it should be some check inside 'each' function so this error won't stop the whole script execution or may be it should produce some warnings.
cause whole script on page stops after some ajax fail
Change History (8)
comment:1 Changed 11 years ago by
Component: | unfiled → core |
---|---|
Keywords: | needsreview added |
Priority: | undecided → low |
Status: | new → open |
Type: | bug → enhancement |
comment:3 Changed 11 years ago by
I like this; it makes unnecessary the jQuery.each( arr || [], ... )
idiom and costs almost nothing.
comment:4 Changed 11 years ago by
The only cost I can see, and it could be a high one, is that we would silently allow undefined to go undetected. In the situation where you actually expect undefined or null, the jQuery.each( arr || [], ... )
documents that clearly.
i spent a lot of time trying to find out the reason
Did the error message in gibson042's test case show up on the console? It seems like it should have. In your program, is undefined a legitimate and anticipated value? If not, it seems like an error message is easier to debug than no message.
comment:5 Changed 11 years ago by
some of my programs treat undefined as legitimate. others will have no problem if such values will be undefined.
as for me, it'll be more intuitive for $.each to do nothing on 'undefined' instead of generating exception;
[]" for until invent something more reasonable |
comment:6 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | open → closed |
Since this has been consistent behavior of $.each()
through several versions, I think we should leave this in the realm of invalid inputs.
comment:8 Changed 11 years ago by
IMHO, the behaviour of $.each is inconsistent with (my perception of) jQuery's robust nature. Method chaining does not "blow up" when results are undefined, the chain fails silently and gracefully, which is how I expected $.each to perform.
As a lazy programmer, testing every variable to see if it's defined before passing it off to something as simple as iterator is an anathaema to me, so I believe that the request for this change is a valid one from a jQuery "user" point of view.
Just because "it's always been that way" does not mean it's right, but I accept the fact that changing this could break legacy code.
I'd be alright with changing that. Let's see what others think.