Is it possible to write a getter that takes a parameter?

In the PureMVC documentation, I found two very strange pieces of code:

public function get resultEntry( index:int ) : SearchResultVO { return searchResultAC.getItemAt( index ) as SearchResultVO; } 

and a bit later:

 var item:SearchResultVO = searchProxy.resultEntry( 1 ); 

(found in Best Practices [English] , bottom of page 38 and top of page 39)

I always thought that getters should not accept a parameter (and the FDT really tells me that "Parameters for getters are not allowed"), so I wonder what is going on here.

Is it just a bad typo (intended to be just a normal function without "get") or some kind of hidden function / voodoo?

+4
source share
1 answer

Usually the only way to achieve this is:

 public function getResultEntry( index:int ) : SearchResultVO { return searchResultAC.getItemAt( index ) as SearchResultVO; } 

The reason is that you get an ActionScript keyword reserved. In fact, it will reveal your function as a public property and expects a predefined format.

This happens in both a strict and non-standard type checking module, so I assume this is a typo in the PureMVC documentation :)

I suggest you write an email at Cliff Hall: P

Greetings

+4
source

All Articles