声明为*(星号)ActionScript变量类型星号、变量、声明、类型

2023-09-08 14:06:52 作者:你的谎言、我不买单

我看到的地方下面的语句 -

I saw following statement somewhere -

var someVariable:*;

为什么 someVariable 的声明为*(星号)类型?有什么用声明这样说吗?

Why is someVariable declared as * (star) type? What is the use of declaring it this way?

推荐答案

之间的实际差异 * 对象 * 未定义,而对象不能。

The practical difference between * and Object is that * can be undefined whereas Object cannot.

该文档已这说:

指定属性是无类型。使用星号的类型注释等效于使用任何类型的注解。从类型化属性读取前pressions被视为无类型EX pressions。使用无类型EX pressions或属性,建议在以下情况:

Specifies that a property is untyped. Use of the asterisk symbol for a type annotation is equivalent to using no type annotation. Expressions that read from untyped properties are considered untyped expressions. Use of untyped expressions or properties is recommended in the following circumstances:   

当你想推迟类型检查到运行时。您可以使用无类型属性或EX pression规避编译时类型检查的严格模式。但是请注意,赋值语句的运行时类型检查时是否使用严格模式还是不行。 actionscript –

When you want to defer type checking to runtime. You can use an untyped property or expression to circumvent compile-time type checking in strict mode. Note, however, that runtime type checking of assignment statements occurs whether you use strict mode or not.

当你想存储未定义的属性的值。与ActionScript的previous版本,值undefined不是Object数据类型的成员。您必须使用无类型属性来存储值undefined。

When you want to store the value undefined in a property. Unlike previous versions of ActionScript, the value undefined is not a member of the Object data type. You must use an untyped property to store the value undefined.