View comments | RSS feed

9.6.6 Bound methods

Although a method is not a value by itself, it can be converted to a first class value called a bound method, through extraction. A bound method maintains the binding between a method and its instance. The user-visible type of a bound method is Function.

class A 
{
    function m() { return this }
}
var a  = new A
var mc : Function = a.m     // create a bound method from m and a
trace(a==mc())   // trace true, mc remembers its this

Comments


Joe@emeraldforest said on Feb 26, 2008 at 12:09 PM :
This seems really similar to the concept of 'Function Pointers'

Basically, mc is a reference (pointer) to a's m function. When mc is called ( mc() ) it is really a.m() that gets called. There is no copy made of the function as might be inferred from the language here.

 

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

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