An untyped variable is not the same as a variable of type Object. The key difference is that untyped variables can hold the special value undefined , while a variable of type Object cannot hold that value.
但是,当我将其测试为:
var objTest:Object = 123;
var untypedTest:* = 123;
objTest = undefined;
untypedTest = undefined;
//This is understandable but why was the assignment even allowed?
trace(objTest); // prints null
trace(untypedTest); // prints undefined
objTest=null;
untypedTest = null;
//This is also understandable ... both can store null
trace(objTest); // prints null
trace(untypedTest); // prints null
//If they are null whey are they being equal to undefined?
if(objTest==undefined)
trace("obj is undefined");
if(untypedTest==undefined)
trace("untyped is undefined");
//Because null is same as undefined!
if(null==undefined)
trace("null is same as undefined?");
两个问题:
最佳答案
一些示例:
var i:int = NaN;
trace (i); // 0
或者:
var b:Boolean = null;
trace(b); // false
所以当你分配
undefined
至 Object
实例 Flash 将其转换为 null
以同样的方式。Boolean
. 您可以使用严格比较来获得
false
:if(null === undefined)
trace("Never traced: null is not the same as undefined!");
关于flash - 无类型变量相对于对象有什么好处? null 和 undefined 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6980349/