首先是“未定义”然后为null,现在为“null” [英] First "undefined" then null and now "null"

查看:77
本文介绍了首先是“未定义”然后为null,现在为“null”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript正在发生什么。


一开始就有未定义。代表一个真正不存在的

对象的值然后出现了null关键字。但是昨天我偶然发现了null。字符串。


我知道我会得到一个未定义的当我尝试从不存在的DOM中检索某些东西时,


我自己使用null来初始化或重置变量。但是在其中

的情况下,Javascript会返回null或null。


还有其他任何我可能不知道的返回值吗?


谢谢

-

* Don Vaillancourt

软件开发总监

*

* WEB IMPACT INC。*

电话:416-815-2000转。 245

传真:416-815-2001

电子邮件:执行** @ web- impact.com < mailto:do ** @ webimpact.com>

web: http://www.web-impact.com


/此电子邮件仅供收件人使用

并包含可能保密和/或
版权的信息。如果您不是预定的收件人请

通过回复电子邮件通知发件人并立即删除

此电子邮件。除预定收件人以外的任何人使用,披露或复制此电子邮件

是严格禁止的b $ b。没有人表示此电子邮件或

任何附件都没有病毒。病毒扫描建议为
,并且是收件人的责任。

/

What''s going on with Javascript.

At the beginning there was the "undefined" value which represented an
object which really didn''t exist then came the null keyword. But
yesterday I stumbled across "null" string.

I know that I will get an "undefined" when I try to retrieve something
from the DOM which doesn''t exist.

I have used null myself to initialize or reset variables. But in which
case would Javascript return a null or "null".

Are there any other return values out there that I may not know about?

Thanks
--
* Don Vaillancourt
Director of Software Development
*
*WEB IMPACT INC.*
phone: 416-815-2000 ext. 245
fax: 416-815-2001
email: do**@web-impact.com <mailto:do**@webimpact.com>
web: http://www.web-impact.com

/ This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.
/

推荐答案

2004年10月27日星期三09:52:53 -0400,Don Vaillancourt< do ** @ webimpact.com>

写道:
On Wed, 27 Oct 2004 09:52:53 -0400, Don Vaillancourt <do**@webimpact.com>
wrote:
什么'继续使用Javascript。


一个相当含糊的问题。

一开始


什么时候开始?

有未定义字样代表一个真正无法存在的对象的值然后出现了null关键字。


你在这里描述的是什么?


当你期望的时候遇到未定义的值 - 当

没有定义的东西。


例如,


alert(window.aNonExistantVariable);
<


函数myFunction(){

返回;

}


alert(myFunction());


因为没有指定返回值。


在我看来,null值用于表示没有对象,

当预期对象引用时。例如,document.getElementById

返回对文档中元素的引用。但是,如果找不到具有指定id的

元素,则会得到null。

但昨天我偶然发现了null。串。


[snip]

我自己使用null来初始化或重置变量。但是在这种情况下Javascript会返回null或null。


没有内置或主机方法会返回字符串,'null'',

来表示操作的结果。

还有其他我不知道的返回值吗?
What''s going on with Javascript.
A rather vague question.
At the beginning
At the beginning of what?
there was the "undefined" value which represented an object which really
didn''t exist then came the null keyword.
What are you actually describing here?

The value, undefined, is encountered when you would expect it - when
something hasn''t been defined.

For example,

alert(window.aNonExistantVariable);

would yield undefined, as would

function myFunction() {
return;
}

alert(myFunction());

because no return value was specified.

The null value is, in my mind, used to signify that there is no object,
when an object reference is expected. For example, document.getElementById
returns a reference to an element within the document. However, if no
element with the specified id can be found, you''ll get null instead.
But yesterday I stumbled across "null" string.
[snip]
I have used null myself to initialize or reset variables. But in which
case would Javascript return a null or "null".
There is no built-in or host method that would return the string, ''null'',
to signify the result of an operation.
Are there any other return values out there that I may not know about?




同样,这是一个非常奇怪的问题。没有标准集。返回

值。 API函数可以在其

规范中返回它所说的任何内容,并且用户定义的函数可以返回任何内容。一个

字符串,一个数字,一个对象(用户定义的,正则表达式,日期或
函数),一个数组,一个布尔值,一个未定义的或null。 br />

我怀疑这有帮助,但由于我不确定你在问什么,这样的结果

并不太令人惊讶。


迈克


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。



Again, a very strange question. There is no "standard set" of return
values. An API function may return anything it says it will in its
specification, and a user-defined function can return anything at all. A
string, a number, an object (user-defined, regular expression, date, or
function), an array, a boolean, undefined, or null.

I doubt that helped, but as I''m not sure what you''re asking, such a result
is not too surprising.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


规则几乎与其他语言相同。


未定义的值意味着请求的对象/属性从未

初始化(不存在)。

window.alert(document.qwertyuiop)> ''undefined''

因此你无法分配未定义的值 - 任何分配(甚至为空)都会使初始化为
,所以它不再是未定义的。


可以为对象/属性分配空值。这意味着它意味着什么 -

null,没有。

var nothing = null;

window.alert(nothing)> ''null'';


本质上,undefined和null非常不同。

在更高级别的语言中,你通常有办法检查一个值是否为

undefined(从不是init)或null(explisetly设置为空)。分别

你必须使用相应的比较方法。

在JavaScript中他们只是简化了比较规则,所以你可以检查

是否存在这样的对象:

如果(obj1.obj2 == null)

这应该是读取类似

如果未定义(obj1) .obj2)


因此,JavaScript中没有直接的方法来检查

从未初始化/设置等于null。

The rules are nearly the same as in other languages.

Undefined value means that the requested object/property was never
initialized (doesn''t exist).
window.alert(document.qwertyuiop) > ''undefined''
Thus you cannot assign undefined value - any assignement (even null) makes
an initialization, so it is not undefined anymore.

Null value can be assigned to an object/property. It means what it means -
null, nothing.
var nothing = null;
window.alert(nothing) > ''null'';

By their nature undefined and null are very different.
In higher level languages you usually have means to check if a value is
undefined (never was init) or null (explisetly set to nothing). Respectively
you have to use the corresponding comparison methods.
In JavaScript they just simplified the comparison rules, so you can check
the existence of an object like this:
if (obj1.obj2 == null)
which is really should be read something like
if undefined(obj1.obj2)

As a consequence there is no direct way in JavaScript to check against
"never initialized"/"set equal to null".


我正在谈论Mozilla和MSIE的Javascript

标准实现方法。


每当您尝试访问不存在的属性时Javascript将

返回undefined串。我明白了。


我已经遇到了一些Javascript方法,这些方法也是如此,我很好,并且总是正在测试。[br / >

但昨天我遇到了一个null我发现奇怪的字符串。我不能告诉我b $ b我打电话给哪个方法来获得这个结果。但是今天我会寻找

,因为我已经写了一个方法来测试所有三个。


Michael Winter写道:
Well I am talking about the standard implemented methods in Javascript
for both Mozilla and MSIE.

Whenever you try to access a property that doesn''t exist Javascript will
return the "undefined" string. That I understand.

I have run into some Javascript methods returning null as well which I''m
okay with and always testing for.

But yesterday I ran into a "null" string which I found odd. I can''t
recall which method I was calling to get this result. But I''ll look for
it today as I have written a method to test against all three.

Michael Winter wrote:
2004年10月27日星期三09:52:53 -0400,Don Vaillancourt
< do ** @ webimpact.com>写道:
On Wed, 27 Oct 2004 09:52:53 -0400, Don Vaillancourt
<do**@webimpact.com> wrote:
Javascript发生了什么。
What''s going on with Javascript.



一个相当含糊的问题。


A rather vague question.

一开始



在什么的开头?


At the beginning of what?

有未定义的表示一个实际上不存在的对象的值然后是null关键字。
there was the "undefined" value which represented an object which
really didn''t exist then came the null keyword.



你在这里实际描述的是什么?



例如,

警告(window.aNonExistantVariable),会遇到未定义的值,即未定义的值。 ;

会产生未定义的,因为

函数myFunction(){
返回;
}

alert(myFunction ());

因为没有指定返回值。

在我看来,null值用于表示没有对象,
期望对象引用。例如,
document.getElementById返回对
文档中元素的引用。但是,如果找不到具有指定id的元素,
你会得到null。


What are you actually describing here?

The value, undefined, is encountered when you would expect it - when
something hasn''t been defined.

For example,

alert(window.aNonExistantVariable);

would yield undefined, as would

function myFunction() {
return;
}

alert(myFunction());

because no return value was specified.

The null value is, in my mind, used to signify that there is no object,
when an object reference is expected. For example,
document.getElementById returns a reference to an element within the
document. However, if no element with the specified id can be found,
you''ll get null instead.

但昨天我偶然发现了null。 string。
But yesterday I stumbled across "null" string.



[snip]


[snip]

我自己用null来初始化或重置变量。但是在
这种情况下Javascript会返回null或null。
I have used null myself to initialize or reset variables. But in
which case would Javascript return a null or "null".



没有内置或主机方法可以返回字符串,
''null''表示操作的结果。


There is no built-in or host method that would return the string,
''null'', to signify the result of an operation.

还有其他我不知道的返回值吗?
Are there any other return values out there that I may not know about?



再一次,一个非常奇怪的问题。没有标准集。返回
值。 API函数可以在其规范中返回它所说的任何内容,并且用户定义的函数可以返回任何内容。
字符串,数字,对象(用户定义的,正则表达式,日期,
或函数),数组,布尔值,未定义或null。

我怀疑这有帮助,但因为我不确定你在问什么,例如结果并不太令人惊讶。

Mike


Again, a very strange question. There is no "standard set" of return
values. An API function may return anything it says it will in its
specification, and a user-defined function can return anything at all.
A string, a number, an object (user-defined, regular expression, date,
or function), an array, a boolean, undefined, or null.

I doubt that helped, but as I''m not sure what you''re asking, such a
result is not too surprising.

Mike



-

* Don Vaillancourt

软件开发总监

*

* WEB IMPACT INC。*

电话:416-815-2000转。 245

传真:416-815-2001

电子邮件:执行** @ web- impact.com < mailto:do ** @ webimpact.com>

web: http://www.web-impact.com


/此电子邮件仅供收件人使用

并包含可能保密和/或
版权的信息。如果您不是预定的收件人请

通过回复电子邮件通知发件人并立即删除

此电子邮件。除预定收件人以外的任何人使用,披露或复制此电子邮件

是严格禁止的b $ b。没有人表示此电子邮件或

任何附件都没有病毒。病毒扫描建议使用
,由接收方负责。

/


--
* Don Vaillancourt
Director of Software Development
*
*WEB IMPACT INC.*
phone: 416-815-2000 ext. 245
fax: 416-815-2001
email: do**@web-impact.com <mailto:do**@webimpact.com>
web: http://www.web-impact.com

/ This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.
/


这篇关于首先是“未定义”然后为null,现在为“null”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆