Side navigation
#9989 closed enhancement (duplicate)
Opened August 05, 2011 02:47PM UTC
Closed August 05, 2011 03:16PM UTC
Last modified March 14, 2012 08:22AM UTC
$.each doesn't check for null
| Reported by: | mjlyco2@gmail.com | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | core | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
var something = ['one', 'two', 'three'];
// some more code
// then woops!
something = null;
$.each(something, function(){
console.log(this);
});
The code above will cause a js error on something.length.
to fix it you need do do the following... maybe this check should be incorporated?
var something = ['one', 'two', 'three'];
// some more code
// then woops!
something = null;
if (something != nul) {
$.each(something, function(){
console.log(this);
});
}
Attachments (0)
Change History (7)
Changed August 05, 2011 03:11PM UTC by comment:1
| component: | unfiled → core |
|---|---|
| milestone: | None → 1.6.3 |
| owner: | → rwaldron |
| priority: | undecided → low |
| status: | new → assigned |
Changed August 05, 2011 03:14PM UTC by comment:2
| resolution: | → wontfix |
|---|---|
| status: | assigned → closed |
Thanks for reporting this, however jQuery cannot account for every possible arbitrary programming structure mistake. I recommend making a check for null before using $.each
Changed August 05, 2011 03:15PM UTC by comment:3
| resolution: | wontfix |
|---|---|
| status: | closed → reopened |
Changed August 05, 2011 03:16PM UTC by comment:4
| resolution: | → duplicate |
|---|---|
| status: | reopened → closed |
Changed August 05, 2011 03:17PM UTC by comment:6
You can also say $.each(something || [], ...) and either indicates to other readers and your later self that you *knew* something could be null. This not only avoids the error, but provides valuable documentation about the program state.
Changed August 26, 2011 01:33AM UTC by comment:7
| milestone: | 1.6.3 |
|---|