Search code examples
actionscript-3functionaccessorfirst-class-functions

How do i refer to a get function as an object


I'd like to reference a get function as a Function object rather than as the value that it returns.

Normally i would be able to simply refer to the function without parenthesizes like so:

private function getFoo():int {
    return 0;
}

trace(getFoo); // traces function

But the whole point of get functions is that you can call the function without the parenthesizes, so i just get a return of 0 if i do this:

private function get foo():int {
    return 0;
}

trace(foo); // traces 0

Is there be any way at all to grab a reference to the foo function object?


Solution

  • Your first example gets a reference to the function (as it traces Function).

    There is no way to get a reference to a getter, as getters are not simple functions, but a representation of a (custom) property of that object. They are not meant to work as a standard ones and so they are not meant to be referenced.

    I cannot imagine why would you want to get a reference to that getter? And also, getters are not meant to be used only because you can skip those two symbols ()..