Thomas 'PointedEars' Lahn said:
Lasse Reichstein Nielsen wrote:
Could be that it does not exist by default, I did not test it but read
about the possibility in dcljs a few days ago. It seems appropriate to
use window.undefined since `undefined' is not a reserved word and it is
unlikely that it has other meaning (in the DOM.)
I don't have access to IE<6, so I can't test it. It is quite possible
that "undefined" is not a global variable (i.e., a property of the
global object, which can also be accessed through the global variable
"window"). It is the case for Netscape 3, and I think I heard it fro
some other browsers too.
It is appropriate to use "window.undefined" for a way to get an
undefined value, since it will work correctly if "undefined" is
defined too.
Who the heck would do that???ßß
Me. If I target platforms where there might not be a global "undefined"
variable, this is the simplest way to make sure there is one. If you want
it to work on the global object without assuming the name "window", you
can write
(function(){this.undefined=this.undefined;})()
If you are going to write "window.undefined" to get an undefined value,
you might as well define it once and for all. This assignment is safe
if "undefined" exists already. As you say, it is appropriate to use
window.undefined to define undefined
I know but `undefined' is not either, since arguments.length changes
when it is used as last argument. And we are talking about arguments
in the middle here.
If we have the function
function foo(a,b,c,d,e) { ... }
and we only want to pass it the first argument
foo(42)
then the values of b through e become undefined. That is the behavior
expected by omitting arguments, which we can do in Javascript.
In Javascript, you cannot omit arguments in the middle. Not even using
foo.apply(this,[1,,,,4]);
If you test with
"3" in arguments
then the third argument is declared and has the value undefined.
(It is browser dependent whether it is defined when you omit arguments
at the end - IE isn't, Opera and Mozilla is)
The closest you can get to omitting arguments must be to give them
the same value as if they had actually been omitted: undefined.
Of course, and that can be helpful.
That's a different point, but then the function must be written to
recognize the parameter passing convention that null represents omission,
not just the null object reference. I think it is misusing null, unless
the argument is supposed to always be an object.
/L