JavaScript中的null是否为对象? [英] Is null an object in JavaScript?

查看:89
本文介绍了JavaScript中的null是否为对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
JavaScript中的空对象

我读过此线程关于JavaScript中的null,但我现在对 null 的身份非常困惑.

Hi, I've read this thread about null in JavaScript, but I'm very confused about the identity of null now.

众所周知,由于 typeof(null)评估为 object rel ="nofollow noreferrer">语言设计错误,并且ECMA指出null为 Null类型.

As it is known that typeof(null) evaluates to object because of the language design error, and ECMA states that null is The Null Type.

   8.2 The Null Type
   The Null type has exactly one value, called null.

那么为什么人们总是说 null 是一个对象?

So why people keep saying that null is an object?

有人说null是一个单例对象.难道每个人也都像JavaScript中那样看到null吗?

Someone said null is a singleton object. Is that how everybody sees the null as in JavaScript too?

推荐答案

Null是缺少对象.未定义表示尚未分配,而null表示已分配为空.

Null is the absence of an object. Undefined means it hasn't been assigned yet, and null means it has been assigned to be nothing.

Null并不是真正的单例对象,因为取消引用它会导致错误. for(var x in null)会给您一个错误.回想一下指针时代;指针未指向对象时具有的值为null.

Null is not really a singleton object, because dereferencing it will cause an error; for (var x in null) will give you an error. Think back to the pointer days; null was the value a pointer had when it was not pointing to an object.

这篇关于JavaScript中的null是否为对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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