zoukankan      html  css  js  c++  java
  • ActionScript中null和undefined的区别 分享

    http://forestinthesea.blog.sohu.com/33648909.html

    The difference between null and undefined is that undefined means the variable was never initialized or has been deleted. You should never *set* a variable to undefined, you should always use null instead, otherwise you ruin the whole distinction between an uninitialized variable and one that you have set to null.

    null和undefined之间的区别在于,undefined意味着变量没有被初始化或者被删除。你永远都不能设置一个undefined的变量,应该使用null来代替,否则你将搞混淆一个未初始化的变量和一个你设置为null的变量之间的区别。

    It is useful to have two different types of "no value assigned", because
    you can tell the difference between a variable that is just currently
    without a value, and one that has either never been assigned a value or has
    been deleted. It is even more useful in complex datatypes.

    尽管从字面上来看都是“尚未指定值”,但是null和undefined是有区别的。因为设置为null的变量只是当前没有值,这表示你可以以后赋予这个变量任何值,但是undefined的变量表示你永远不可能赋予这个变量任何值。这在复杂的数据类型中非常有用。
    var o:Object;
    trace(o); // undefined
    o = new Object(); // initialize
    trace(o); // [Object object]
    o = String("blah"); // assign a primitive as an object
    trace(o); // blah
    o = String(""); // set to empty string
    trace(o); // (empty string, *not* undefined)
    o = null; // empty it
    trace(o); // null
    delete o; // destroy it
    trace(o); // undefined

    So you can see, it can be useful to be able to make the distinction between a variable that has been initialized and then emptied, and a variable that has never been initialized. The most common place to do this is in something like this:

    所以可以看到,能够区别一个已经初始化但是置空的变量和一个尚未初始化的变量之间的区别是非常有用的。

  • 相关阅读:
    容器操作--管理迭代器
    顺序容器--添加及访问元素
    日志记录-20151103
    顺序容器--容器库.迭代器
    使用-flat.vmdk恢复虚拟机
    H3C-交换机维护命令大全
    Centos6.5 安装zabbix-agent 3.0
    Linux系统调试工具之sysdig使用详解
    通过实例学习 tcpdump 命令
    系统之锹sysdig:Linux服务器监控和排障利器
  • 原文地址:https://www.cnblogs.com/xiayong123/p/3717023.html
Copyright © 2011-2022 走看看