Skip to content

Proposals

Matheus Dias de Souza edited this page May 5, 2024 · 2 revisions

Syntax

Miscellaneous listed here.

Enumerations

An enumeration is a final class defining a series of static constants that are instances of that class.

An instance of an enumeration maps to a String and a Number.

Enum1("memberName")
Enum1(0)

Enum1.MEMBER_NAME.toString() // "memberName"
Enum1.MEMBER_NAME.valueOf() // 0

An enumeration is not allowed to define a constructor.

An enumeration defines an arbitrary set of properties, both static, and at the class prototype.

Attributeless const definitions containing optional ASDoc comments, found within the enum block, define members of the enumeration. The initializer of a member is optional, and may be in one of the following forms.

StringLiteral
numberConstant
[StringLiteral, numberConstant]
[numberConstant, StringLiteral]

If the StringLiteral is omitted, it is deduced as a conversion of the screaming-snake-case form of the constant name (SCREAMING_SNAKE_CASE) to a camel-case form (camelCase).

If the numberConstant is omitted, it is deduced as the valueOf() of the previously defined member + 1, or 0.

It is a verify error if either the StringLiteral or numberConstant are duplicate across the members.

enum Enum1 {
    const M1
        , M2 = 1
        , M3 = "m3"
        , M4 = [12, "m4"]
        , M5 = ["m5", 28]
}

Enum1.M1 returns an Enum1 object where toString() == "m1" and valueOf() == 0.

Type inference occurs when a context expects exactly an enumeration and the expression is a StringLiteral, whose value is limited to match the String of an enumeration member.

var k : Enum1 = "memberName";
var k = Enum1("memberName");

Options Classes

An options class is a class containing the [Options] meta-data. Such a class may be initialized from an object initializer through direct type inference.

Note: options classes are common for defining options that a method or constructor may receive.

A property is optional when it includes either null, undefined, or a default value (always the case in standard ActionScript 3.0).

A property would not be optional when it is of a non-nullable data type such as in the T! proposal, which excludes null from a reference.

[Options]
class MyC1 {
    var property: Number;
}
var o1 : MyC1 = {
    property: 10,
};
var o2 : * = MyC1({
    property: 10,
});

This proposal implies that the call operator T(...) for type conversions passes T as the context type of the conversion argument.

The call operator is required where a context accepts more than one type rather than only a specific [Options] class, such as Object or * typed variables.

Clone this wiki locally