Is it possible to write a getter that takes a parameter?
I've found two very strange pieces of code in PureMVC's documentation:
public function get resultEntry( index:int ) : SearchResultVO
{
return searchResultAC.getItemAt( index ) as SearchResultVO;
}
and bit later:
var item:SearchResultVO = searchProxy.resultEntry( 1 );
(found in Best Practices [English], bottom of page 38 and top of page 39)
I've always thought that getters must not accept a parameter (and FDT indeed tells me that "Parameters for getters are not allowed"), so I wonder what's going on here.
开发者_开发百科Is that just an unfortunate typo (meant to be simply a normal function without the "get") or some hidden feature/voodoo?
Normally the only way to achieve this is as follows:
public function getResultEntry( index:int ) : SearchResultVO
{
return searchResultAC.getItemAt( index ) as SearchResultVO;
}
The reason is because get is reserved ActionScript keyword. It will in fact expose your function as a public property and expects a predefined format.
It occurs in both strict an non strict type checking modus, so I am guessing that it is a typo in the PureMVC documentation :)
I suggest that you write an email to Cliff Hall then :P
Cheers
精彩评论