9.6.3 Instance methods

Functions declared without the static attribute add a method trait to the instance traits of a class object. Static and instance variables are in scope of an instance method. The value of this inside an instance method is the instance the method is bound to.

class A 
{
    function m() { return this }
}
var a = new A
trace(a==a.m())   // trace true, this is the object 'm' is called on

In addition to the attributes defined for all class properties, the following attributes may be used on instance methods

final

May not be overridden

override

Must override an inherited method

The override attribute helps to avoid unintentional overriding of base class methods. It is a verifier error to use the override attribute on a function definition that does not override an inherited method. It is a verifier error to override an inherited method that is declared final. It is an error to define a method without the override attribute if the name matches the name of an inherited method.

The prototype attribute allows the addition of a fixed property to the prototype object, but not to the instance. Instance methods defined with the prototype attribute have function values that are compatible with ECMA-262 edition 3 prototype functions.

class A 
{
    prototype var f = function() { return this }
}
var a = new A
dynamic class B {}
var b = new B
b.f = a.f
b.f()   // traces "[object B]"

The instance of B becomes the value of this.


 

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

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