actionscript-3 - * 和 Object 有什么区别

标签 actionscript-3

假设我有一个具有一些属性的类:

public class MyClass {
   public var fooProp:*;
   public var barProp:Object;
}

实际上,这些之间有什么区别?是否有我以后可以分配给 fooProp 而不能分配给 barProp 的变量类型?

最佳答案

只有无类型变量才能保存值 undefined .无类型变量是缺少任何类型注释或使用星号 * 的变量。类型注释的符号。

From ActionScript data type descriptors :

In previous versions of ActionScript, a variable with no type annotation was automatically assigned the Object data type. This is no longer true in ActionScript 3.0, which now includes the idea of a truly untyped variable. Variables with no type annotation are now considered untyped. If you prefer to make it clear to readers of your code that your intention is to leave a variable untyped, you can use the new asterisk (*) symbol for the type annotation, which is equivalent to omitting a type annotation. The following example shows two equivalent statements, both of which declare an untyped variable:

var x 
var x:*

Only untyped variables can hold the value undefined. If you attempt to assign the value undefined to a variable that has a data type, Flash Player or Adobe AIR will convert the value undefined to the default value of that data type. For instances of the Object data type, the default value is null, which means that Flash Player or Adobe AIR will convert the value undefined to null if you attempt to assign undefined to an Object instance.



举个例子:
var t:* = undefined;
trace(t); // outputs: undefined

var t:Object = undefined;
trace(t); // outputs: null

关于actionscript-3 - * 和 Object 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16933565/

相关文章:

flash - ActionScript 的 WordWrap 打破单词

android - 在 Air Mobile 中加载外部交互式 swf

actionscript-3 - 如何将图像发送到 AS3 中

actionscript-3 - 从特定的一组数字生成随机数 as3

algorithm - 自动旋转房子的底部到直线

flash - Actionscript 错误 #2044 : Unhandled SecurityErrorEvent:. text=Error #2047 : Security sandbox violation: LocalConnection. 发送 : 127. 0.0.1 无法访问

actionscript-3 - AS3 字符串到类

android - 当手机改变方向时,Air Android 应用程序崩溃

actionscript-3 - 如何修复浮点不精确的输出?

java - 如何找到控制点贝塞尔曲线