#1055 closed defect (fixed)
dojo.lang.isUndefined() fix for really undefined objects
Reported by: | Owned by: | Tom Trenka | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Core | Version: | 0.3 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Is there a reason that isUndefined is structured the way it is, such that an undefined variable/object will throw an error.
dojo.lang.isUndefined = function(wh){
return ((wh == undefined)&&(typeof wh == "undefined"));
}
if you do
dojo.lang.isUndefined(foo);
with no other reference to foo in your code it'll throw a JS error, becuase JS doesn't like checking for objects that don't exist, rather preferring you to checkf ro properties of existing objects.
so...
dojo.lang.isUndefined(window.foo);
will return False as expected.
One idea I had was that if you did:
dojo.lang.isUndefined = function(wh){
return ((typeof wh == "undefined") (wh == undefined));
}
That way actual real undefined objects will not fail, but will return false as expected. My logic being that I assume we're testing for two possible states, if the first in the above two is true it won't even try to do the second one (which throws the error) because we're using an OR, but if it doesn't it'll just check the second possible undefined to cover bases.
Thoughts?
Change History (4)
comment:1 Changed 16 years ago by
Milestone: | → 0.4 |
---|
comment:2 Changed 16 years ago by
Owner: | changed from anonymous to Tom Trenka |
---|
comment:3 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [5494]) Fixes #1055 by swapping the truth arguments around.