Difference between custom metadata and static functions?

Custom metadata in ActionScript classes is very cool. You can put everything in square brackets in front of classes, functions, and variables; tell the compiler to include it (by name) in SWF; and use describeType () to get it.

[MyMetaData(name1=value1, name2=value2)]

Add to Additional Compiler Arguments

-keep-as3-metadata+=MyMetaData

And use describeType () to find those elements with this metadata

var typeDescriptionXML : XML = flash.utils.describeType(aType);

var itemsWithMyMetaData : XMLList = 
    classXML.factory.metadata.(@name == "MyMetaData");

Static functions, on the other hand, are pretty straightforward:

public static function myStaticFunction() : Object
{
    var result : Object = new Object({name1: "value1", name2: "value2"});
    return result;
}

Although I would like static functions to be virtual, they do what they should do.


What is the advantage of metadata for static functions for class level elements?

+3
source share
2

, , . describeType , , , XML.

, , , . , Object, , . Object , , . :

public static function myStaticFunction():Object
{
    return { name1: "value1", name2: "value2" };
}

, :

package
{
public class StaticClass
{
    private static const SOME_DATA:int = 0;
    private static const SOME_STRING:String = "Hello World";

    private static var count:int = 0;

    public static function printCount():void
    {
        trace(SOME_STRING, SOME_DATA, count++);
    }
}

}

, (, , ), , Flex (, , , ), .

+3

. : ...

, , classMetaData, :

for each (var c:Class in arrayOfClass) 
     trace(c.getData());

:

for each (var c:* in arrayOfClass) 
     trace(c.getData());

, , EVERY , c.getData() *...

describeType ... , , , XMLList, ... - - , ... , , ...

, , : - actionscript ... 100% , , , ...

Greetz

back2dos

+3

Source: https://habr.com/ru/post/1715917/


All Articles