4.18 Trait

A trait is a fixed property shared by all instances of the same type. The collection of traits defines the invariants of the object's type. For this reason, use the traits object to describe the type of an object. Traits are declared in the definition of the class used to create an object.

class A 
{
    var x
    function m() { }
    function get y() { return 10 }
    function set y(v) { }
}

Each member of this class definition causes a trait to be added to the traits object for instances of A. When an instance is created by class A, the resulting object has the properties x, m, and y, implemented by traits for var x, function m, function get y and function set y.

Traits express the type of an instance. All traits are copied down to the derived traits objects. All traits must be implemented. Interface members are abstract and so their traits must be implemented in any class that inherits them.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification43.html